mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-11 17:54:06 +02:00
reset "file current position" on errors
If an error occurs while sending a file to the API (e.g. 401), the io handle is reused and the current postion is at the end of the file. This results in an empty value. This patch takes care that the current file postion gets resetted if a retransmission is required.
This commit is contained in:
@@ -296,6 +296,9 @@ def http_request(method, url, headers=None, data=None, file=None):
|
|||||||
# prompt user if we should trust the certificate
|
# prompt user if we should trust the certificate
|
||||||
pool.trusted_cert_store.prompt_trust(cert, reason=e.reason)
|
pool.trusted_cert_store.prompt_trust(cert, reason=e.reason)
|
||||||
|
|
||||||
|
if hasattr(data, 'seek'):
|
||||||
|
data.seek(0)
|
||||||
|
|
||||||
response = pool.urlopen(
|
response = pool.urlopen(
|
||||||
method, urlopen_url, body=data, headers=headers,
|
method, urlopen_url, body=data, headers=headers,
|
||||||
preload_content=False, assert_same_host=assert_same_host
|
preload_content=False, assert_same_host=assert_same_host
|
||||||
@@ -307,6 +310,8 @@ def http_request(method, url, headers=None, data=None, file=None):
|
|||||||
success = handler.set_request_headers_after_401(url, headers, response)
|
success = handler.set_request_headers_after_401(url, headers, response)
|
||||||
if success:
|
if success:
|
||||||
break
|
break
|
||||||
|
if hasattr(data, 'seek'):
|
||||||
|
data.seek(0)
|
||||||
response = pool.urlopen(method, urlopen_url, body=data, headers=headers, preload_content=False)
|
response = pool.urlopen(method, urlopen_url, body=data, headers=headers, preload_content=False)
|
||||||
|
|
||||||
if response.status / 100 != 2:
|
if response.status / 100 != 2:
|
||||||
|
Reference in New Issue
Block a user