我试图用poster模块发送图像。我跟着例子,但它不工作我Python海报内容长度错误
我的代码:
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)
而且回溯:
`File "decaptcha.py", line 27, in <module>
decaptcha(None)
File "decaptcha.py", line 24, in decaptcha
solve = urllib2.urlopen(req, datagen, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 390, in open
req = meth(req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster-0.8.1-py2.7.egg/poster/streaminghttp.py", line 154, in http_request
"No Content-Length specified for iterable body")
ValueError: No Content-Length specified for iterable body`
对不起,我的代码格式化不好,我会尝试修复它。 – Meph
非常感谢Aamir的格式化 – Meph