Python 使用请求模块访问api
curl命令按预期工作。但类似的python代码却没有Python 使用请求模块访问api,python,python-3.x,Python,Python 3.x,curl命令按预期工作。但类似的python代码却没有 # curl -X POST -H "Content-Type: application/json" -d '{"img_url":"http://tleyden-misc.s3.amazonaws.com/blog_images/ocr_test.pnge","engine":"tesseract"}' http://35.154.148.131:9292/ocr 预期产出: You can create local variables
# curl -X POST -H "Content-Type: application/json" -d '{"img_url":"http://tleyden-misc.s3.amazonaws.com/blog_images/ocr_test.pnge","engine":"tesseract"}' http://35.154.148.131:9292/ocr
预期产出:
You can create local variables for the pipelines within the template by
prefixing the variable name with a "$" sign. Variable names have to be
composed of alphanumeric characters and the underscore. In the example
below I have used a few variations that work for variable names.
我尝试了以下python代码:
import requests
url = 'http://35.154.148.131:9292'
data = {"img_url":"http://tleyden-misc.s3.amazonaws.com/blog_images/ocr_test.png","engine":"tesseract"}
r = requests.post( url, json={'json_payload': data})
这将返回以下错误:
b'<h1>OpenOCR is running!<h1> Need <a href="http://www.openocr.net">docs</a>?'
b'OpenOCR正在运行!需要吗?”
如何使用数据参数发布字典?我就是这样做到的:
import requests
url = 'http://35.154.148.131:9292/ocr'
data = {"img_url":"http://tleyden-misc.s3.amazonaws.com/blog_images/ocr_test.png","engine":"tesseract"}
r = requests.post( url, json=data )
结果
u'You can create local variables for the pipelines within the template by\nprefixing the variable name with a "$" sign. Variable names have to be\ncomposed of alphanumeric characters and the underscore. In the example\nbelow I have used a few variations that work for variable names.\n\n'
只调用
r=requests.post(url,json=data)
怎么样?据我所知,这是使用它的方式。另外,在Python代码中,URL中缺少/ocr
端点。
u'You can create local variables for the pipelines within the template by\nprefixing the variable name with a "$" sign. Variable names have to be\ncomposed of alphanumeric characters and the underscore. In the example\nbelow I have used a few variations that work for variable names.\n\n'