flickrapi.auth.OAuthFlickrInterface error during upload
rodmur opened this issue · 2 comments
I'm seeing the following issue when I try to upload, it will do several images before it craps out. Am I just handling the oauth authentication wrong? Or do I just need to add code to re-attempt the upload?
File: DSC_0267.png
No handlers could be found for logger "flickrapi.auth.OAuthFlickrInterface"
Traceback (most recent call last):
File "/Users/rodmur/bin/flickrup2.py", line 45, in
flickr.upload(filename=fname,title=tit,tags=mytags,is_public=0,callback=func)
File "/Library/Python/2.7/site-packages/flickrapi/core.py", line 494, in upload
return self._upload_to_form(self.UPLOAD_URL, filename, fileobj, timeout=timeout, **kwargs)
File "/Library/Python/2.7/site-packages/flickrapi/core.py", line 544, in _upload_to_form
filename, form_url, kwargs, fileobj, timeout=timeout)
File "/Library/Python/2.7/site-packages/flickrapi/core.py", line 399, in _wrap_in_parser
data = wrapped_method(*args, **kwargs)
File "/Library/Python/2.7/site-packages/flickrapi/auth.py", line 307, in do_upload
raise exceptions.FlickrError('do_upload: Status code %s received' % req.status_code)
flickrapi.exceptions.FlickrError: do_upload: Status code 500 received
Here's the code, I won't claim it's good, but it has worked in the past:
#!/usr/bin/python
import flickrapi
import os
import sys
api_key='XXXXXXXXXXX'
api_secret='XXXXXX'
mydir = sys.argv[1]
taglist = sys.argv[2:]
mytags = " ".join(taglist)
print "tags: %s" % mytags
flickr = flickrapi.FlickrAPI(api_key, api_secret)
flickr.authenticate_via_browser(perms='write')
def func(progress, done):
if done:
print "Done uploading"
else:
print "At %s%%" % progress
files = sorted([f for f in os.listdir(mydir) if not f.startswith('.')])
for name in files:
fname = os.path.join(mydir, name)
print "File: %s" % name
tit = name.split('.')[0]
flickr.upload(filename=fname,title=tit,tags=mytags,is_public=0,callback=func)
Hi @rodmur, best if you present your code indented and marked with python
keyword like this. Check notes here!
def func(progress, done):
if done:
print "Done uploading"
else:
print "At %s%%" % progress
Now to your question, based on this link, I understand error 500 to be a server error. So I suggest to retry the operation.
You can also wrap the upload around try/except
sequence to catch additional error situations.
Check this gist and
this somehow complex (I know... still cleaning it up a bit...once I have the time) example of such code here
I found situations in which Flickr refuses to accept some files due to their format (in particular some videos) or size.
okay, fixed the markdown, at least. I'll look into the gist, thanks!