开发者

IO error when attempting to download images from url

The error happens when executing the following lines,

output[counter] = h['url']
name = '%(name)s%(#)03u' % {'title': user_input, '#': counter}
urllib.urlretrieve(output[counter], name)
counter += 1

>>>> File "/base/python_runtime/python_dist/lib/python2.5/urllib.py", line 225, in retrieve
>>> tfp = open(filename, 'wb')
>>> IOError: invalid mode: wb

Ive got a few errors beofre due to google's app engine not 开发者_如何学Gosupporting any version above 2.5, not sure if that is what is causing it.

Thank you for your help!


Found what I was looking for here, I apologize for not finding it before posting this question.

Python app engine: how to save a image?


Python is going to be looking for 'name' in the replacement dictionary you give it, not 'title'

name = '%(name)s%(#)03u' % {'name' : 'title', '#' : counter}


It looks like urlfetch is trying to open a temporary file to store the result of the urlfetch in. Is the resulting page large? We recently increased the max size of a URLFetch operation to 32MB, from 1MB, so it's possible this is a new bug only visible with large responses. Please file a bug. In the meantime, you should use the URLFetch API directly, which is both more flexible and doesn't suffer from this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜