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

发布于 2024-08-11 05:17:18 字数 2134 浏览 8 评论 0原文

我正在尝试编写一个小工具来将图片从 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 为:

Traceback(最近一次调用最后一次):

File "/home/birt/stuff/google/appengine/ext/webapp/init.py", line 507, in 打电话 handler.get(*groups)

文件“/home/birt/stuff/app_picasaupload/main.py”,第 124 行,在 get 中 uploadpicture(comment, pic)

文件“/home/birt/stuff/app_picasaupload/main.py”,第 104 行,在 uploadpicture 中 Entry = gd_client.InsertPhotoSimple(album_url, fname, comment, pic, content_type='image/jpeg')

文件“/home/birt/stuff/app_picasaupload/gdata/photos/service.py”,第 469 行,在 InsertPhotoSimple 中 content_type)

文件“/home/birt/stuff/app_picasaupload/gdata/photos/service.py”,第 398 行,InsertPhoto os.path.exists(filename_or_handle): # 这是一个文件名

File "/usr/lib/python2.5/posixpath.py", line 171, in contains st = os.stat(path)

文件“/home/birt/stuff/google/appengine/tools/dev_appserver.py”,第 1109 行,调用 如果不是 FakeFile.IsFileAccessible(path):

文件“/home/birt/stuff/google/appengine/tools/dev_appserver.py”,第 1018 行,位于 IsFileAccessible normcase=normcase)

文件“/home/birt/stuff/google/appengine/tools/dev_appserver.py”,第 1036 行,位于 _IsFileAccessibleNoCache if os.path.isdir(逻辑文件名):

文件“/usr/lib/python2.5/posixpath.py”,第 195 行,在 isdir 中 st = os.stat(path)

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

有什么想法吗? :-)

I'm trying to write a small tool to upload Pictures from Google App Engine to Picasa. Fetching the image works, but when i try to upload it i get the error "TypeError: stat() argument 1 must be (encoded string without NULL bytes), not str"

The Code basically looks like this:

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)

The full Stacktrace is:

Traceback (most recent call last):

File "/home/birt/stuff/google/appengine/ext/webapp/init.py", line 507, in call
handler.get(*groups)

File "/home/birt/stuff/app_picasaupload/main.py", line 124, in get
uploadpicture(comment, pic)

File "/home/birt/stuff/app_picasaupload/main.py", line 104, in uploadpicture
entry = gd_client.InsertPhotoSimple(album_url, fname, comment, pic, content_type='image/jpeg')

File "/home/birt/stuff/app_picasaupload/gdata/photos/service.py", line 469, in InsertPhotoSimple
content_type)

File "/home/birt/stuff/app_picasaupload/gdata/photos/service.py", line 398, in InsertPhoto
os.path.exists(filename_or_handle): # it's a file name

File "/usr/lib/python2.5/posixpath.py", line 171, in exists
st = os.stat(path)

File "/home/birt/stuff/google/appengine/tools/dev_appserver.py", line 1109, in call
if not FakeFile.IsFileAccessible(path):

File "/home/birt/stuff/google/appengine/tools/dev_appserver.py", line 1018, in IsFileAccessible
normcase=normcase)

File "/home/birt/stuff/google/appengine/tools/dev_appserver.py", line 1036, in _IsFileAccessibleNoCache
if os.path.isdir(logical_filename):

File "/usr/lib/python2.5/posixpath.py", line 195, in isdir
st = os.stat(path)

TypeError: stat() argument 1 must be (encoded string without NULL bytes), not str

Any Ideas ? :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2024-08-18 05:17:18

这个问题的解决方案是使用 StringIO :-)

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

添加

pic = StringIO.StringIO(pic)

会将来自 urlfetch 的 result.content 转换为 gdata 期望的类似文件的格式。

The Solution to this problem was using StringIO :-)

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

adding

pic = StringIO.StringIO(pic)

converts the result.content from urlfetch into a file-like format gdata expects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文