我无法通过Google App Engine从我的应用发送电子邮件.我遇到了几个新的障碍,我将非常感谢你的帮助.
我从教程中获取此功能,对于"发件人"字段,我将我用于创建应用程序的gmail帐户放入:
mail.send_mail(sender="owners_email_acco...@gmail.com",
to="xxxx...@gmail.com",
subject="test email from app",
body="hello")
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我得到错误:
InvalidSenderError: Unauthorized sender
Run Code Online (Sandbox Code Playgroud)
但电子邮件
sender="owners_email_acco...@gmail.com",
Run Code Online (Sandbox Code Playgroud)
是我用来登录应用程序的电子邮件; 这是我用来创建应用程序的电子邮件.
教程说:
The email address of the sender, the From address. The sender address must be one of the following types: The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.
所以我用来创建应用程序的电子邮件应该作为发件人.我究竟做错了什么?谢谢.
(我在GAE小组中问同样的问题,但没有回复)
我使用这一行传递a url,main_id并user_tag_list传递给处理程序:
self.response.out.write("""
<a href="/tc?url=%s&main_id=%s&user_tag_list=%s" title="edit tag set">edit tag set</a>
""" %
(item.url, main_id, item.tag_list))
Run Code Online (Sandbox Code Playgroud)
当已经有一个问号在通过这项工作,除了罚款url(第一个参数)我再也不能得到main_id与
main_id = self.request.get("main_id")
Run Code Online (Sandbox Code Playgroud)
在目标处理程序中,我得到错误
m = Main.get_by_id(int(main_id))
ValueError: invalid literal for int() with base 10: ''
Run Code Online (Sandbox Code Playgroud)
有没有解决的办法?
这是我之前的问题的后续跟进.
我正在使用Chrome扩展程序http://ting-1.appspot.com/将书签页面保存到Google App Engine后端.看看Chrome网上商店,我看到扩展程序有一个"添加到Chrome"按钮.由于我的扩展程序需要与后端进行通信(因此用户必须拥有gmail帐户才能使用此扩展程序)如何在扩展程序中指明使用用户名(将扩展程序添加到Chrome的人员的gmail地址)来编写用他的用户ID添加谷歌应用引擎的书签?我的理解上有差距,我似乎没有在文档中找到与此问题相关的任何内容.我background.html在下面.谢谢.
background.html
<html>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab) {
// Send a request to the content script.
chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) {
var firstParagraph = response.dom;
console.log("background -- before *console.log(response.dom)*")
console.log("this is *console.log(response.dom)*: " + response.dom)
console.log("background -- after *console.log(response.dom)*")
//}); moved to end to get the variable firstParagraph
var formData = new FormData();
formData.append("url", tab.url);
formData.append("title", tab.title);
formData.append("pitch", firstParagraph);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true);
xhr.onreadystatechange = function …Run Code Online (Sandbox Code Playgroud) 这是Scrapy教程中的BaseSpider示例:
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from dmoz.items import DmozItem
class DmozSpider(BaseSpider):
domain_name = "dmoz.org"
start_urls = [
"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
]
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//ul[2]/li')
items = []
for site in sites:
item = DmozItem()
item['title'] = site.select('a/text()').extract()
item['link'] = site.select('a/@href').extract()
item['desc'] = site.select('text()').extract()
items.append(item)
return items
SPIDER = DmozSpider()
Run Code Online (Sandbox Code Playgroud)
我为我的项目更改了它:
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.item import Item
from firm.items import FirmItem …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关接收邮件的教程.我按照说明更新了app.yaml文件:
application: hello-1-world
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
- url: /_ah/mail/.+
script: handle_incoming_email.py
login: admin
- url: /.*
script: hw.py
inbound_services:
- mail
Run Code Online (Sandbox Code Playgroud)
并创造了一个 handle_incoming_email.py
import cgi
import os
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
class ReceiveEmail(InboundMailHandler):
def receive(self,message):
logging.info("Received email from %s" % message.sender)
plaintext = message.bodies(content_type='text/plain')
for …Run Code Online (Sandbox Code Playgroud) 这是我之前的问题(未解决)的后续问题.
我items从数据库中取出并在for循环中显示它们.我使用jQuery来隐藏其中一行.现在我需要获取main_id隐藏的行并传递给它$.ajax.在Paul建议使用的原始问题中,alert(this.attr("title"));但是这一行会停止执行$.ajax调用,并且不会执行调用.当我注释掉警报时alert(this.attr("title"));,ajax调用就会通过.在这种情况下,我得到一个错误,因为display_false()处理程序中的函数没有得到的值main_id.
这是"隐藏"链接的html title=%s.
<a class="false" title=%s href="/useradminpage?main_id=%s&display=false"><span class="small">(hide)</span></a>
Run Code Online (Sandbox Code Playgroud)
所以我需要main_id在执行ajax调用时将存储的值传递alert(this.attr("title"));给函数display_false().
我怎样才能做到这一点?
相关代码如下:
剧本
self.response.out.write("""
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
<title>User Admin Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
alert("1 - document ready is called")
$("a.false").click(function(e) {
$(this).closest("tr.hide").hide("slow");
e.preventDefault();
alert("2 - row is hidden")
});
$("a.false").click(function() {
alert("3 - ajax")
//the following alert …Run Code Online (Sandbox Code Playgroud) 我有一个列表属性
tag_list = db.StringListProperty()
Run Code Online (Sandbox Code Playgroud)
到目前为止,这一直工作正常,但今天当我尝试写一个包含18个项目的列表时,我收到了Too many indexed properties for entity:错误.我认为这是"爆炸指数"的一个例子.
这是我的查询:
query = Main.all()
query.filter("url =", url)
query.filter("owner =", user)
Run Code Online (Sandbox Code Playgroud)
阅读文档我的理解是,如果列表中有2000多个项目,将触发此错误.如果这是针对18个项目触发的,那么,我做错了什么以及如何解决这个问题?谢谢.
使用更多代码更新:
query = Main.all()
query.filter("url =", url)
query.filter("owner =", user)
e = query.get()
if e:
e.tag_list = user_tag_list
e.pitch = pitch_original
e.title = title_ascii
e.put()
main_id = e.key().id()
else:
try:
new_item = Main(
url = url,
tag_list = user_tag_list,
pitch = pitch_original,
owner = user,
#title = unicode(title, "utf-8"),
title = title_ascii,
display = True)
#this is …Run Code Online (Sandbox Code Playgroud) 我在Chrome扩展程序中使用了Channel API.
在Google App Engine渠道API Javascript参考(Python)页面中,它说明了这一点
在引用它的任何JavaScript代码之前,在您的html页面中包含以下内容:
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
Run Code Online (Sandbox Code Playgroud)
所以,我把它放在我的options.html文件的标题中:
<html>
<head>
<title>Extension Options</title>
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
但Chrome会抛出jsapiFailed to load resource错误.我究竟做错了什么?
更新
根据Moishe的回答,我更新了对jsapi的调用,如下所示:
<head>
<title>Extension Options</title>
<!-- this does not work because it is local
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
更新
我添加了onopen其他属性.现在我收到onopen警报,但我没有得到evt.data警报.我究竟做错了什么?
<html>
<head>
<title>Extension Options</title>
<!-- this does not work because it is local url
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
<body> …Run Code Online (Sandbox Code Playgroud) 我正在阅读Caleb Doxsey的Go书,我有两个关于http://www.golang-book.com/4的问题fmt.Scanf
我想知道为什么程序在第二个Scanf之后没有停止并等待用户输入?如何测试用户输入的整数和/或是否留空?
package main
import (
"fmt"
//"math"
)
// compute square roots by using Newton's method
func main() {
var x float64 //number to take square root
var y float64 //this is the guess
var q float64 //this is the quotient
var a float64 //this is the average
// how do check if the user entered a number
fmt.Print("Enter a number to take its square root: ")
var inputSquare float64
fmt.Scanf("%f", &inputSquare)
// why doesn't …Run Code Online (Sandbox Code Playgroud) expt我正在尝试根据此答案使用函数,但是当我尝试在 REPL 中执行操作时(use 'clojure.math.numeric-tower),出现错误
user> (use 'clojure.math.numeric-tower)
(use 'clojure.math.numeric-tower)FileNotFoundException Could not locate clojure/math/numeric_tower__init.class or clojure/math/numeric_tower.clj on classpath: clojure.lang.RT.load (RT.java:443)
Run Code Online (Sandbox Code Playgroud)
我想我需要将 Leiningen 依赖信息放入此处解释的
[org.clojure/math.numeric-tower "0.0.2"]
Run Code Online (Sandbox Code Playgroud)
在我的中project.clj,我这样做了,但仍然遇到同样的错误。我究竟做错了什么?
编辑
正如在这个答案中我转到我的项目目录并做了lein deps
a@b:~/command-line-args$ lein deps
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.pom from central
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.jar from central
a@b:~/command-line-args$
Run Code Online (Sandbox Code Playgroud)
但我在 REPL 中仍然遇到同样的错误。
编辑2
根据 Vidya 的回答,我正在尝试使用石榴,但没有成功。这就是我尝试过的。我究竟做错了什么:
user> (use '[cemerick.pomegranate :only (add-dependencies)])
nil
user> (add-dependencies :coordinate '[[org.clojure/math.numeric-tower "0.0.2"]]
:repositories (merge cemerick.pomegranate.aether/maven-central
{"clojars" "http://clojars.org/repo"}))
{}
user> (require '(numeric-tower core stats charts)) …Run Code Online (Sandbox Code Playgroud) python ×4
javascript ×2
clojure ×1
dependencies ×1
email ×1
go ×1
jquery ×1
leiningen ×1
query-string ×1
scrapy ×1
web-crawler ×1