1

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?

1
  • How about calling just r = requests.post( url, json=data)? According to documentation that's the way to use it. Also, in your Python code, you are missing the /ocr endpoint in the URL. Commented Jan 8, 2018 at 9:15

2 Answers 2

2

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 )
Sign up to request clarification or add additional context in comments.

Comments

1
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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.