我试图用poster模块发送图像。我学了这个例子,但对我不管用
我的代码:
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib, urllib2
def decaptcha(hash):
register_openers()
params = {
"file": open("captcha.jpg", "rb"),
"function" : "picture2",
"username" : "uname",
"password" : "pwd",
"pict_to" : 0,
"pict_type" : 0
}
datagen, headers = multipart_encode(params)
req = urllib2.Request("http://poster.decaptcher.com/")
solve = urllib2.urlopen(req, datagen, headers)
print solve.read()
decaptcha(None)
以及回溯:
^{pr2}$
您应该将datagen和headers传递给请求,而不是urlopen:
(免责声明:我没有使用海报库。建议的解决方案是我的最佳猜测。)
从海报上看,这似乎是可行的。在
我将尝试以下方法(传递文件的内容而不是打开文件迭代器,应该可以解决iterable body问题):
建议2:
或者试试: 从多部分编码导入MultiPartParam
^{pr2}$如果由于相同的错误而失败,请尝试将
filesize
参数指定给MultiPartParam
。在相关问题 更多 >
编程相关推荐