-3

I've been trying to do a retrieval in python

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Doomer
  • 1
  • 1
  • You don't have access to the `/tmp/` directory (odd). Try running Python with `sudo`. – Blender Nov 14 '11 at 16:56
  • @Blender: the script has access to `/tmp` otherwise there would be no `download_file(item)` in the traceback. It would fail sooner. – jfs Nov 14 '11 at 16:59
  • @J.F.Sebastian: What do you mean? The traceback points to the first line that accesses `/tmp/`. – Blender Nov 14 '11 at 17:16
  • @Blender: note: `23` line is *before* `13` (recursive call) – jfs Nov 14 '11 at 17:30
  • @J.F.Sebastian: Oh, I completely missed that recursive call (facepalm) – Blender Nov 14 '11 at 17:31
  • I figured out that I have no access to Footemp as it is owned by another user. So i had to create Attretrieve instead of Footemp and own that myself. Apparently, it works for the other user but still doesn't work for me. :( – Doomer Nov 14 '11 at 21:54
  • Also, the idea is to read from the list of file name, and retrieve each file into a target directory. I am not sure how much disk space the documents will take up; so we might want to modify the program to retrieve the files just to check the size, but not to store them. – Doomer Nov 14 '11 at 21:56

2 Answers2

2
  • the second argument to urlretrieve() is a filename not a directory.
  • you're ignoring docid argument
  • you probably don't want to call download_file() recursively
  • `folder_size` (with backtick) is a syntax error

Here's a script that downloads documents specified in /tmp/docids to /tmp/Footemp directory (it must exist):

outdir = "/tmp/Footemp"
with open("/tmp/docids") as f:
     for line in f:
         docid = line.strip()
         if not docid: continue # skip empty lines
         name = urllib.parse.quote_plus(docid)
         url = "http://foo.com/doc/" + name
         path = os.path.join(outdir, name)
         name, info = urllib.request.urlretrieve(url, path)
         print(info)

See Calculating a directory size using Python?

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670
0

The code looks to be correct, so it is likely a permissions error. Try saving to a file in a directory that you know you have write access to.

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485