使用 Python http 请求而不是 INT 获取 <response[200]>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43354200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting <response[200]> with Python http requests instead of INT
提问by user3281831
Im trying to create simple python code that would communicate with 9kw.eu captcha solving service through their api https://www.9kw.eu/api.html#apisubmit-tab. Basically I'm sending base64 encoded image with some keys:values and response from server should be number like: 58952554, but I'm only getting
我试图创建简单的 python 代码,通过他们的 api https://www.9kw.eu/api.html#apisubmit-tab与 9kw.eu 验证码解决服务通信。基本上我正在发送带有一些键的 base64 编码图像:来自服务器的值和响应应该是数字,例如:58952554,但我只得到
<response[200]>
Which should mean that the server got my data, but im not getting anything else. I'm able to get the right result with simple html form:
这应该意味着服务器得到了我的数据,但我没有得到其他任何东西。我能够使用简单的 html 表单获得正确的结果:
<form method="post" action="https://www.9kw.eu/index.cgi" enctype="multipart/form-data">
KEY:<br>
<input name="apikey" value="APIKEY"><br>
ACTION<br>
<input name="action" value="usercaptchaupload"><br>
FILE:<br>
<input name="file-upload-01" value="BASE64IMAGEDATAHERE"><br>
TOOL<br>
<input name="source" value="htmlskript"><br>
ROTATE<br>
<input name="rotate" value="1"><br>
Angle<br>
<input name="angle" value="40"><br>
BASE64
<input name="base64" value="1"><br>
Upload:<br>
<input type="submit" value="Upload and get ID">
</form>
This is the python code, which should do the same thing:
这是python代码,它应该做同样的事情:
import requests
import time
#base64 image encoding
with open("funcaptcha1.png", "rb") as f:
data = f.read()
filekodovany = data.encode("base64")
#captcha uploader
udajepost = {'apikey':'APIKEY','action':'usercaptchaupload','file-upload-01':filekodovany,'source':'pythonator','rotate':'1','angle':'40','base64':'1'}
headers = {'Content-Type':'multipart/form-data'}
r = requests.post('https://www.9kw.eu/index.cgi', data = udajepost)
print(r)
Thanks for any help.
谢谢你的帮助。
回答by Ahsanul Haque
r = requests.post('https://www.9kw.eu/index.cgi', data = udajepost)
Here, r
is the whole response object which has many attributes. I guess, you only need r.text
. So, you can just use:
在这里,r
是具有许多属性的整个响应对象。我想,你只需要r.text
. 所以,你可以使用:
print(r.text)
回答by TurqSpl
You're looking for the response of the request:
您正在寻找请求的响应:
print(r.text)
In this way you'll have the plain text response.
通过这种方式,您将获得纯文本响应。