0

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 supporting 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?

Community
  • 1
  • 1
evelima
  • 25
  • 5

2 Answers2

2

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

name = '%(name)s%(#)03u' % {'name' : 'title', '#' : counter}
MStodd
  • 4,716
  • 3
  • 30
  • 50
  • 'title' actually a var in the real code, i changed it because i though it did not matter...the error comes from the line urllib.urlretrieve(output[counter], name) but idk why... – evelima Dec 09 '10 at 23:16
0

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.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • It should be large, i'm trying to save images from an url address the images size vary but should be much less than 32MB. Thank you for your help. I will look into the URLFetch API. – evelima Dec 10 '10 at 02:38
  • I am not sure if I can use URLFetch to do the job. I am trying to save images to a file from their HTML address. The same code works fine when executing locally not sure what is the problem, dont have much experience. – evelima Dec 10 '10 at 02:53
  • @evelima On App Engine, httplib and urllib(2) are wrappers around URLFetch. Anything you can do with either of those can be done with URLFetch. If you're trying to write to a local file, though, you can't do that on App Engine - you need to write to the datastore instead. App Engine apps can be served off a whole cluster of machines, so writing to local disk wouldn't make sense even if it were allowed. – Nick Johnson Dec 13 '10 at 01:18