【发布时间】:2009-11-11 14:38:24
【问题描述】:
我正在尝试编写一个小工具来将图片从 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(最近一次调用最后一次):
文件“/home/birt/stuff/google/appengine/ext/webapp/init.py”,第 507 行,在 call 中 handler.get(*groups)
文件“/home/birt/stuff/app_picasaupload/main.py”,第 124 行,在 get 上传图片(评论,图片)
文件“/home/birt/stuff/app_picasaupload/main.py”,第 104 行,在上传图片中 entry = gd_client.InsertPhotoSimple(album_url, fname, comment, pic, content_type='image/jpeg')
文件“/home/birt/stuff/app_picasaupload/gdata/photos/service.py”,第 469 行,在 InsertPhotoSimple 中 内容类型)
InsertPhoto 中的文件“/home/birt/stuff/app_picasaupload/gdata/photos/service.py”,第 398 行 os.path.exists(filename_or_handle): # 是文件名
文件“/usr/lib/python2.5/posixpath.py”,第 171 行,存在 st = os.stat(路径)
调用中的文件“/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(logical_filename):
文件“/usr/lib/python2.5/posixpath.py”,第 195 行,在 isdir 中 st = os.stat(路径)
TypeError: stat() 参数 1 必须是(没有 NULL 字节的编码字符串),而不是 str
有什么想法吗? :-)
【问题讨论】:
-
如果没有实际代码和完整的堆栈跟踪,这是不可能的。
-
您是否有可能使用 Python 3?这就是错误消息所暗示的。 appengine SDK 专门支持(当然也支持生产版本;-)Python 2.5,目前不支持更高版本。
-
这不是你最初所说的例外。正如异常所暗示的那样,您似乎在尝试获取无效的 URL。
-
对不起尼克,我首先发布了错误的 Stacktrace - 已修复 :)
-
Alex:我正在使用 python2.5 明确启动 SDK
标签: python google-app-engine gdata-api typeerror picasa