【问题标题】:Uploading into blobstore using urlfetch使用 urlfetch 上传到 blobstore
【发布时间】:2014-07-21 13:52:14
【问题描述】:

我正在尝试上传使用谷歌应用引擎 urlfetch 从 url 获取的 excel。我可以访问它的所有标题。我现在需要将相同的内容上传到 blobstore。以下是我写的代码

class Send_Handler(webapp2.RequestHandler):
    def get(self):
        url = "http://abc.xls"
        result = None
        fetch_(url, result, 'GET') 
        #     self.response.out.write(result.content)

def fetch_(url, result, method):
    # logging.info(result)
    if method=='GET':
        result = urlfetch.fetch(url)
        if result.status_code == 200:
            upload_url = blobstore.create_upload_url('/attachupload')
            logging.info(upload_url)
            fetch_(upload_url, result, 'POST')
    else:
        try:
            r_headers = result.headers
            logging.info(result.content)
            result_2 = urlfetch.fetch(url=url, payload=result.content,method=urlfetch.POST, headers=r_headers)
            # logging.info(result_2)
        except Exception, e:
            logging.error(e)

运行时返回错误“TypeError: not indexable

以下是我得到的标题

替代协议:80:quic,80:quic 服务器:谷歌前端 传输编码:分块 日期:2014 年 7 月 21 日星期一 13:18:16 GMT 内容类型:应用程序/msexcel 缓存控制:无缓存 内容传输编码:二进制 内容处置:附件;文件名="abc.xls"

这个excel文件的url是从另一个webapp获取的

【问题讨论】:

  • fetch_thing的代码在哪里?
  • 检查下面的答案,因为您需要对您的帖子进行编码,因为它是一个 html 表单才能上传到 blob。

标签: python google-app-engine urlfetch


【解决方案1】:

几个月前我写了this Gist,关于使用upload_url 和urlfetch 将blob 上传到blobstore。示例代码从 blobstore 中读取现有的 blob。

要将 blob 发送到 blobstore,您必须发送多部分/表单数据。

【讨论】:

    猜你喜欢
    • 2012-03-05
    • 2011-09-19
    • 2012-03-20
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多