0

I have this curl command, and I would like to transform it into a python request (including the query):

curl -u user:pwd123 -s -G --data-urlencode "q=GET services\nColumns: column1 column2 column3\nFilter: column1 ~~ stringtofilter\nFilter: column2 ~~ string2\nFilter: string3 ~~ string3tofilter" http://myendpoint.inet/api/query?

To convert it to python I can do this:

import requests

response = requests.get('http://myendpoint.inet/api/query', auth=('user', 'pwd123'))

But how can I include my query inside?

aldegalan
  • 480
  • 2
  • 12
  • I use sometimes this site https://curl.trillworks.com/ , just when I feel too lazy to write it myself :) – Christian Dec 02 '20 at 20:33

1 Answers1

0

I found the way to do that:

response = requests.get('http://myendpoint.inet/api/query', params = "q=GET services\nColumns: column1 column2 column3\nFilter: column1 ~~ stringtofilter\nFilter: column2 ~~ string2\nFilter: string3 ~~ string3tofilter", auth=("user", "pwd123"))

To see if the command is successful: print (response) It must return <Response [200]>

To see the response:

print (response.text)
aldegalan
  • 480
  • 2
  • 12