我正在尝试编写一个小工具,将图片从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
有什么想法吗?:-)
这个问题的解决方案是使用StringIO:-)
(http://docs.python.org/library/stringio.html)
添加
转换结果.内容从urlphetch到gdata期望的格式的文件中。在
相关问题 更多 >
编程相关推荐