Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过urlfetch将图像插入Python Google应用程序引擎Sdk中的Picasa_Python_Google App Engine_Http_Picasa_Urlfetch - Fatal编程技术网

通过urlfetch将图像插入Python Google应用程序引擎Sdk中的Picasa

通过urlfetch将图像插入Python Google应用程序引擎Sdk中的Picasa,python,google-app-engine,http,picasa,urlfetch,Python,Google App Engine,Http,Picasa,Urlfetch,我尝试通过Google App Engine Sdk将Flex应用程序中的图像插入picasa web。我想做一个简单的urlfetch,而不是python客户端库。守则一如下: def Insert(self, sessionToken, album_or_uri, title, filename_or_handle): result = urlfetch.fetch(url=album_or_uri, m

我尝试通过Google App Engine Sdk将Flex应用程序中的图像插入picasa web。我想做一个简单的urlfetch,而不是python客户端库。守则一如下:

    def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
        result = urlfetch.fetch(url=album_or_uri,
                                method=urlfetch.POST,
                                follow_redirects=True,
                                payload=StringIO(filename_or_handle),
                                headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
                                'Content-Length': str(len(filename_or_handle)),
                                'Content-Type': 'image/jpeg',
                                'Slug': title
                                })
def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
    image = filename_or_handle.read()
    contentLength = len(image)
    result = urlfetch.fetch(url=album_or_uri,
                method=urlfetch.POST,
                follow_redirects=True,
                payload=image,
                headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
                'Content-Length': contentLength,
                'Content-Type': 'image/jpeg',
                'Slug': title
                })
传递到“filename\u或\u handle”的数据是ByteArray图像。然而,它并不成功。我不知道是什么问题。请给我一些建议。谢谢

解决办法如下:

    def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
        result = urlfetch.fetch(url=album_or_uri,
                                method=urlfetch.POST,
                                follow_redirects=True,
                                payload=StringIO(filename_or_handle),
                                headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
                                'Content-Length': str(len(filename_or_handle)),
                                'Content-Type': 'image/jpeg',
                                'Slug': title
                                })
def Insert(self, sessionToken, album_or_uri, title, filename_or_handle):
    image = filename_or_handle.read()
    contentLength = len(image)
    result = urlfetch.fetch(url=album_or_uri,
                method=urlfetch.POST,
                follow_redirects=True,
                payload=image,
                headers={'Authorization': 'AuthSub token="' + sessionToken + '"',
                'Content-Length': contentLength,
                'Content-Type': 'image/jpeg',
                'Slug': title
                })

谢谢,约翰逊。

有效负载应该是字符串,而不是类似文件的对象。它应该如何编码取决于您正在调用的API——请参阅文档中的API来确定它,以及您需要设置的任何其他标题等。您不太可能需要对其进行base64编码,只需直接将图像内容传递进来即可


如果你仍然有问题,你必须比“它不成功”更具体一些-你得到了什么回应?

@Johnson,谢谢你的回复。我通过pyamf从flex应用程序传递数据。图像作为ByteArray加载到flex应用程序中,我将其传递给应用程序引擎。base64只是一个测试。请同时查看更新。@michael更新后我回答了这个问题。正如我所说的,您应该将图像数据作为原始字符串加载,并将其作为有效负载直接传入。如果你仍然有问题,请提供更多细节。@Johnson,也许这是个愚蠢的问题。在我的例子中,bytearray图像数据可以接受吗。谢谢。@michael Python没有“ByteArray”。也许您应该在问题中包含该片段,以说明如何获取数据。@michael,然后您需要使用
filename\u或\u handle.read()
,获取图像数据,并将其传递进来。您还需要对数据本身而不是句柄调用
len