Skip to content

Commit a1ee2e8

Browse files
committed
fix: always set value of response in timed_request()
1 parent f0871c2 commit a1ee2e8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

commonpy/network_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def addurl(text):
145145
elif client == 'stream':
146146
client = httpx.stream
147147

148+
response = None
148149
failures = 0
149150
error = None
150151
while failures <= _MAX_CONSECUTIVE_FAILS and not interrupted():
@@ -187,7 +188,7 @@ def addurl(text):
187188
if not error:
188189
error = ex
189190
# If there's response text, it may contain diagnostic info.
190-
if __debug__:
191+
if __debug__ and response:
191192
text = response.text[:500] + (' ...' if len(response.text) > 500 else '')
192193
log('response text: ' + text)
193194
if failures == 0:
@@ -243,7 +244,7 @@ def net(method, url, client=None, handle_rate=True,
243244
This method always passes the argument follow_redirects = True to the
244245
underlying Python HTTPX library network calls.
245246
'''
246-
import httpx
247+
import httpx
247248

248249
if method.lower() not in _KNOWN_HTTP_METHODS:
249250
raise ValueError(f'Method must be one of {", ".join(_KNOWN_HTTP_METHODS)}.')

0 commit comments

Comments
 (0)