【发布时间】:2014-07-13 21:12:03
【问题描述】:
我是 Python 新手。我有一个在谷歌应用引擎上运行的脚本。它使用 urllib3 与 api 对话。它在我的计算机上完美运行,但失败并给了我一个
“错误:[Errno 10054] 现有连接被强行关闭 远程主机”
我做了一些研究,最好的答案似乎是异常处理。我该怎么做?
for row in rows:
address = row['emailaddress']
status = row['status']
location = row['location']
if status != 'Active':
status = 'Inactive'
payload = '{xxx}'
r = http.urlopen('POST', url, body=payload, headers={'Content-Type': 'application/json'})
【问题讨论】:
-
为什么你使用 urllib3 连接池在 appengine 上不起作用,除非你使用套接字/计费。如果你想要某种程度的并发(你的例子确实如此)那么你应该考虑使用异步请求developers.google.com/appengine/docs/python/urlfetch/…