将 curl 命令转换为 python?
Converting curl command to python?
我有这个 curl 命令,我想将它转换成 python 请求(包括查询):
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?
要将其转换为 python 我可以这样做:
import requests
response = requests.get('http://myendpoint.inet/api/query', auth=('user', 'pwd123'))
但是我怎样才能在里面包含我的查询呢?
我找到了这样做的方法:
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"))
查看命令是否成功:
打印(响应)
必须return<Response [200]>
查看回复:
print (response.text)
我有这个 curl 命令,我想将它转换成 python 请求(包括查询):
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?
要将其转换为 python 我可以这样做:
import requests
response = requests.get('http://myendpoint.inet/api/query', auth=('user', 'pwd123'))
但是我怎样才能在里面包含我的查询呢?
我找到了这样做的方法:
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"))
查看命令是否成功:
打印(响应)
必须return<Response [200]>
查看回复:
print (response.text)