Python 分段上传未占用 content-type
Python multipart upload not taking content-type
我打算使用 python 请求框架进行分段上传,下面是我的代码:
import requests
def myfc()
{
url = "https://myurl"
payload={}
files=[
('request',('test.yaml',open('/Users/test/test.yaml'))
]
headers = {
'Content-Type': 'multipart/form-data',
'Authorization': 'test'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files,verify=False)
print(response.text)
}
print(' 1')
t1 = threading.Thread(target=myfc, args=())
print(' 2')
t2 = threading.Thread(target=myfc, args=())
print(' 3')
t3 = threading.Thread(target=myfc, args=())
t1.start()
如果我从 headers 中删除 'Content-Type': 'multipart/form-data',只保留授权,那么它工作正常,但如果我保留 'Content-Type': 'multipart/form-data' ,然后它给出 404 response.Why so?
尝试以下操作:
import requests
def myfc():
url = "https://myurl"
payload={}
files= {
'test.yaml' : open('/Users/test/test.yaml', 'r')
}
headers = {
'Content-Type': 'multipart/form-data',
'Authorization': 'test'
}
with requests.request("POST", url, headers=headers, data=payload, files=files,verify=False) as response:
response.raise_for_status()
print(response.text)
print(' 1')
t1 = threading.Thread(target=myfc, args=())
print(' 2')
t2 = threading.Thread(target=myfc, args=())
print(' 3')
t3 = threading.Thread(target=myfc, args=())
t1.start()
我打算使用 python 请求框架进行分段上传,下面是我的代码:
import requests
def myfc()
{
url = "https://myurl"
payload={}
files=[
('request',('test.yaml',open('/Users/test/test.yaml'))
]
headers = {
'Content-Type': 'multipart/form-data',
'Authorization': 'test'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files,verify=False)
print(response.text)
}
print(' 1')
t1 = threading.Thread(target=myfc, args=())
print(' 2')
t2 = threading.Thread(target=myfc, args=())
print(' 3')
t3 = threading.Thread(target=myfc, args=())
t1.start()
如果我从 headers 中删除 'Content-Type': 'multipart/form-data',只保留授权,那么它工作正常,但如果我保留 'Content-Type': 'multipart/form-data' ,然后它给出 404 response.Why so?
尝试以下操作:
import requests
def myfc():
url = "https://myurl"
payload={}
files= {
'test.yaml' : open('/Users/test/test.yaml', 'r')
}
headers = {
'Content-Type': 'multipart/form-data',
'Authorization': 'test'
}
with requests.request("POST", url, headers=headers, data=payload, files=files,verify=False) as response:
response.raise_for_status()
print(response.text)
print(' 1')
t1 = threading.Thread(target=myfc, args=())
print(' 2')
t2 = threading.Thread(target=myfc, args=())
print(' 3')
t3 = threading.Thread(target=myfc, args=())
t1.start()