【问题标题】:how to send the bits of an image by requests.post (url, data) in webapp2如何通过webapp2中的requests.post(url,data)发送图像的位
【发布时间】:2012-10-09 16:15:09
【问题描述】:

我的网址太长,它会抛出错误:

ConnectionError: HTTPConnectionPool(host='xxxx', port=8086): Max retries exceeded with url: /user/profile?nick=nick&name=xxx&city=xxx&gender=x&profile_image=%FF%D8%FF%E0%00%10JFIF%00%01%01%01%00%60%00%60%00%00%...

我正在将图像上传到文件 iput 并尝试通过 requests.post 传递它,但它抛出了上面的错误。

我的代码是这样的:

profile_image = self.request.get("f_profile_image")
    data = {"id": id_user,
                "nick": nick,
                "name": name,
                "last_name": last_name,
                "gender": gender,
                "profile_image": profile_image}

    d = requests.post("http://myhost:8086/user/profile",params=data)
    self.response.out.write(d.text)

我在这里得到图片 profile_image = self.request.get("f_profile_image") 我从表单发送,并尝试将其发送到我的服务器以存储在数据库中。但是 d = requests.post("http://myhost:8086/user/profile",params=data) 犯了我上面提到的错误

【问题讨论】:

  • 您可能想展示一些代码来说明您是如何执行此操作的。看起来您正在尝试对图像进行编码并将其发送到 POST url,这很容易使 URL 太长。您想将图像放入 POST 数据中。
  • 当您像图像一样发布数据时,您必须将其作为多部分消息发布在有效负载中。看到这个问题:stackoverflow.com/questions/10066540/… 查看您的代码。您从表单中收到图像。为什么不将图像上传到服务器? developers.google.com/appengine/docs/python/blobstore/…

标签: google-app-engine webapp2


【解决方案1】:

大家好,发生错误是因为它没有在我的模型中引入良好的数据类型,后来他们理解错误消息对我没有多大帮助,我相信错误在其他地方也有,谢谢您的反馈。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多