我需要在python中执行以下CURL请求:
curl -X POST https://fake.url
-H 'apiKey: {apiKey}'
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{ "data": { "dirname": "{dirname}", "basename": "{filename}", "contentType": "application/octet-stream" } }'
我通过通过pip安装的“请求”模块实现了这一点:
try:
import requests
except ImportError:
os.system("pip install requests")
import requests
...
url = 'https://fake.url'
headers = {
'apiKey': f'{apiKey}',
'Content-Type': 'application/json',
'Accept': 'application/json',
}
payload = json.dumps({
'data': {
'dirname': f'{dirname}',
'basename': f'{filename}',
'contentType': 'application/octet-stream'
}
})
response = requests.post(url, headers=headers, data=payload)
客户要求不要使用pip来安装“请求”模块。是否有可能做到这一点?或者,是否可以在没有“请求”模块的情况下执行CURL请求?