shantanuo
shantanuo

Reputation: 32294

using requests module to access api

The curl command works as expected. But similar python code does not.

# 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

Expected output:

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.

I tried this python code:

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})

This returns the following error:

b'<h1>OpenOCR is running!<h1> Need <a href="http://www.openocr.net">docs</a>?'

How do I post the dictionary using data parameter?

Upvotes: 1

Views: 75

Answers (2)

Jishnunand P K
Jishnunand P K

Reputation: 290

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.get(url, json=data) 
r.text

Result

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'

Upvotes: 1

shantanuo
shantanuo

Reputation: 32294

This is how I managed to do this:

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 )

Upvotes: 2

Related Questions