Question

Je suis en train d'écrire un petit outil pour télécharger des photos de Google App Engine vers Picasa. Récupérer l'image fonctionne, mais lorsque je tente de le télécharger i l'erreur " TypeError: Argument stat () 1 doit être (chaîne codée sans octets NULL), pas str "

Le code ressemble fondamentalement à ceci:

def getfile(url):
    result = urlfetch.fetch(url)
    if result.status_code == 200:
        return (result.content)
    logging.error ("[-] Error fetching URL: %s" % url)

def uploadpicture(comment,pic):
    album_url = '/data/feed/api/user/%s/album/%s' % (username, album)
    fname = "image.jpg"
    entry = gd_client.InsertPhotoSimple(album_url, fname, comment, pic, content_type='image/jpeg')

picurl = "http://brilliantleap.com/blog/frog.jpg"
pic = getfile(picurl)
comment = "Test"
uploadpicture(comment, pic)

Le Stacktrace complet est:

retraçage (appel le plus récent en dernier):

Fichier "/home/birt/stuff/google/appengine/ext/webapp/init.py", ligne 507, Appel     handler.get (* groupes)

Fichier "/home/birt/stuff/app_picasaupload/main.py", ligne 124, en get     uploadpicture (commentaire, pic)

Fichier "/home/birt/stuff/app_picasaupload/main.py", ligne 104, en uploadpicture     entrée = gd_client.InsertPhotoSimple (ALBUM_URL, fname, commentaire, pic, content_type = 'image / jpeg')

Fichier "/home/birt/stuff/app_picasaupload/gdata/photos/service.py", ligne 469, en InsertPhotoSimple     content_type)

Fichier "/home/birt/stuff/app_picasaupload/gdata/photos/service.py", ligne 398, en insertphoto     os.path.exists (filename_or_handle): # il est un nom de fichier

Fichier "/usr/lib/python2.5/posixpath.py", ligne 171, en existe     st = os.stat (trajet)

Fichier "/home/birt/stuff/google/appengine/tools/dev_appserver.py", ligne 1109, Appel     sinon FakeFile.IsFileAccessible (path):

Fichier "/home/birt/stuff/google/appengine/tools/dev_appserver.py", ligne 1018, en IsFileAccessible     normcase = normcase)

Fichier "/home/birt/stuff/google/appengine/tools/dev_appserver.py", ligne 1036, en _IsFileAccessibleNoCache     si os.path.isdir (logical_filename):

Fichier "/usr/lib/python2.5/posixpath.py", ligne 195, en isdir     st = os.stat (trajet)

TypeError: Argument stat () 1 doit être (chaîne codée sans octets NULL), pas str

Des idées? : -)

Était-ce utile?

La solution

La solution à ce problème utilisait StringIO: -)

( http://docs.python.org/library/stringio.html )

ajoutant

pic = StringIO.StringIO(pic)

convertit le result.content de urlfetch dans un format de fichier comme gdata attend.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top