简体   繁体   中英

Converting curl command to python?

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM