简体   繁体   English

将 curl 命令转换为 python?

[英]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 命令,我想将其转换为 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?

To convert it to python I can do this:要将其转换为 python 我可以这样做:

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]>查看命令是否成功: print (response) 必须返回<Response [200]>

To see the response:要查看响应:

print (response.text)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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