尝试使用GData API将图片从Google App Engine上载到Picasa时出现类型错误

2024-10-01 11:25:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试编写一个小工具,将图片从Google App Engine上传到Picasa。获取图像是可行的,但是当我试图上传它时,我得到错误“TypeError:stat()argument 1 must be(encoded string without NULL bytes),not str

代码基本上如下所示:

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)

完整的Stacktrace是:

回溯(最近一次呼叫):

File“/home/birt/stuff/google/appengine/ext/webapp/init.py”,第507行,在call 处理程序.get(*组)

File“/home/birt/stuff/app_picasaupload”文件/主.py“,第124行,在get中 上传图片(评论,图片)

File“/home/birt/stuff/app_picasaupload”文件/主.py“,第104行,上传图片 入口=gd_client.InsertPhotoSimple(相册_url,fname,comment,pic,content_type='image/jpeg')

File“/home/birt/stuff/app_picasaupload/gdata/photos”/服务.py,第469行,InsertPhotoSimple中 内容类型)

File“/home/birt/stuff/app_picasaupload/gdata/photos”/服务.py“,第398行,插入照片中 os.path.exists(文件名或句柄):#是一个文件名

文件“/usr/lib/python2.5/posixpath.py“,第171行,存在 st=操作系统统计(路径)

File“/home/birt/stuff/google/appengine/tools/dev”_应用服务器.py“,第1109行,in调用 如果没有FakeFile.IsFileAccessible文件(路径):

File“/home/birt/stuff/google/appengine/tools/dev”_应用服务器.py“,第1018行,在IsFileAccessible中 normcase=normcase)

File“/home/birt/stuff/google/appengine/tools/dev”_应用服务器.py“,第1036行,在\u IsFileAccessibleNoCache中 如果操作系统路径.isdir(逻辑文件名):

文件“/usr/lib/python2.5/posixpath.py,第195行,在isdir中 st=操作系统统计路径(p)

TypeError:stat()参数1必须是(没有空字节的编码字符串),而不是str

有什么想法吗?:-)


Tags: 文件pyappurlhomealbumgooglecomment