如何使用Python实现图片上传到Post平台?

更新于
2026-07-31 11:40:59
11阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计122个文字,预计阅读时间需要1分钟。

如何使用Python实现图片上传到Post平台?

从 poster 库中导入 multipart_encode 函数,并注册 streaminghttp 模块中的 openers。导入 urllib2 模块。注册 openers 函数。

from poster.encode import multipart_encode
from poster.streaming192.168.0.158:806/API/Det', datagen, headers)
#print urllib2.urlopen(request).read()

#datagen, headers = multipart_encode( [("key", "value1"), ("key", "value2")] )

a=[ ('Img1', open('1.jpg', 'rb')) ,('Img2', open('2.jpg', 'rb')) ]

datagen, headers = multipart_encode( a )
for i in range(100):
request = urllib2.Request('192.168.0.158:806/API/TwoImage', datagen, headers)
print urllib2.urlopen(request).read()





如何使用Python实现图片上传到Post平台?

本文共计122个文字,预计阅读时间需要1分钟。

如何使用Python实现图片上传到Post平台?

从 poster 库中导入 multipart_encode 函数,并注册 streaminghttp 模块中的 openers。导入 urllib2 模块。注册 openers 函数。

from poster.encode import multipart_encode
from poster.streaming192.168.0.158:806/API/Det', datagen, headers)
#print urllib2.urlopen(request).read()

#datagen, headers = multipart_encode( [("key", "value1"), ("key", "value2")] )

a=[ ('Img1', open('1.jpg', 'rb')) ,('Img2', open('2.jpg', 'rb')) ]

datagen, headers = multipart_encode( a )
for i in range(100):
request = urllib2.Request('192.168.0.158:806/API/TwoImage', datagen, headers)
print urllib2.urlopen(request).read()





如何使用Python实现图片上传到Post平台?