【发布时间】:2016-06-09 21:41:02
【问题描述】:
我正在使用 urllib2.urlopen 从慢速服务器请求一个大小约为 14MB 的文件,它花费了 60 多秒来获取数据,我收到了错误:
等待来自 URL 的 HTTP 响应时已超过截止日期: http://bigfile.zip?type=CSV
这是我的代码:
class CronChargeBT(webapp2.RequestHandler):
def get(self):
taskqueue.add(queue_name = 'optimized-queue', url='/cronChargeBTB')
class CronChargeBTB(webapp2.RequestHandler):
def post(self):
url = "http://bigfile.zip?type=CSV"
url_request = urllib2.Request(url)
url_request.add_header('Accept-encoding', 'gzip')
urlfetch.set_default_fetch_deadline(300)
response = urllib2.urlopen(url_request, timeout=300)
buf = StringIO(response.read())
f = gzip.GzipFile(fileobj=buf)
...work with the data insiste the file...
我创建了一个调用 CronChargeBT 的 cron 任务。这里是 cron.yaml:
- description: cargar BlueTomato
url: /cronChargeBT
target: charge
schedule: every wed,sun 01:00
它创建一个新任务并插入一个队列,这里是队列配置:
- name: optimized-queue
rate: 40/s
bucket_size: 60
max_concurrent_requests: 10
retry_parameters:
task_retry_limit: 1
min_backoff_seconds: 10
max_backoff_seconds: 200
当然,timeout=300 不起作用,因为 GAE 中的 60 秒限制,但我认为我可以使用任务来避免它...任何人都知道我如何获取文件中的数据以避免此超时。
非常感谢!!!
【问题讨论】:
标签: python-2.7 google-app-engine urllib2