8000 Provide a timeout to all download scripts · unho/python-stdnum@975d508 · GitHub
[go: up one dir, main page]

Skip to content

Commit 975d508

Browse files
committed
Provide a timeout to all download scripts
1 parent ed37a6a commit 975d508

15 files changed

+17
-17
lines changed

update/at_postleitzahl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
if __name__ == '__main__':
49-
response = requests.get(download_url)
49+
response = requests.get(download_url, timeout=30)
5050
response.raise_for_status()
5151
data = response.json()
5252
# print header

update/be_banks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_values(sheet):
7777

7878

7979
if __name__ == '__main__':
80-
response = requests.get(download_url)
80+
response = requests.get(download_url, timeout=30)
8181
response.raise_for_status()
8282
workbook = xlrd.open_workbook(file_contents=response.content)
8383
sheet = workbook.sheet_by_index(0)

update/cfi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def print_attributes(attributes, index=0):
7575

7676
if __name__ == '__main__':
7777
# Download the page that contains the link to the current XLS file
78-
response = requests.get(download_url)
78+
response = requests.get(download_url, timeout=30)
7979
response.raise_for_status()
8080
# Find the download link
8181
document = lxml.html.document_fromstring(response.content)
8282
links = [a.get('href') for a in document.findall('.//a[@href]')]
8383
link_url = next(a for a in links if re.match(r'.*/cfi/.*xlsx?$', a))
8484
# Download and parse the spreadsheet
85-
response = requests.get(link_url)
85+
response = requests.get(link_url, timeout=30)
8686
response.raise_for_status()
8787
workbook = xlrd.open_workbook(file_contents=response.content)
8888

update/cn_loc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def fetch_data():
5858
"""Return the data from tab-separated revisions as one code/name dict."""
5959
data_collection = OrderedDict()
6060
for revision in data_revisions:
61-
response = requests.get('%s/raw/release/%s.txt' % (data_url, revision))
61+
response = requests.get('%s/raw/release/%s.txt' % (data_url, revision), timeout=30)
6262
response.raise_for_status()
6363
if response.ok:
6464
print('%s is fetched' % revision, file=sys.stderr)

update/cz_banks.py

Lines changed: 1 addition & 1 deletion
6D40
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_values(csv_reader):
4848

4949

5050
if __name__ == '__main__':
51-
response = requests.get(download_url)
51+
response = requests.get(download_url, timeout=30)
5252
response.raise_for_status()
5353
csv_reader = csv.reader(StringIO(response.content.decode('utf-8')), delimiter=';')
5454
print('# generated from %s downloaded from' % os.path.basename(download_url))

update/do_whitelists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def handle_zipfile(f):
7070
# Download and read the ZIP file with valid data
7171
with tempfile.TemporaryFile() as tmp:
7272
# Download the zip file to a temporary file
73-
response = requests.get(download_url, stream=True)
73+
response = requests.get(download_url, stream=True, timeout=30)
7474
response.raise_for_status()
7575
print('%s: %s' % (
7676
os.path.basename(download_url),

update/eu_nace.py

Lines changed: 1 addition & 1 deletion
9E88
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
if __name__ == '__main__':
37-
response = requests.get(download_url)
37+
response = requests.get(download_url, timeout=30)
3838
response.raise_for_status()
3939
content_disposition = response.headers.get('content-disposition', '')
4040
filename = re.findall(r'filename=?(.+)"?', content_disposition)[0].strip('"')

update/gs1_ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def fetch_ais():
4242
headers = {
4343
'User-Agent': user_agent,
4444
}
45-
response = requests.get(download_url, headers=headers)
45+
response = requests.get(download_url, headers=headers, timeout=30)
4646
document = lxml.html.document_fromstring(response.content)
4747
element = document.findall('.//script[@type="application/ld+json"]')[0]
4848
for entry in json.loads(element.text)['@graph']:

update/iban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_country_codes(line):
4444

4545

4646
if __name__ == '__main__':
47-
response = requests.get(download_url)
47+
response = requests.get(download_url, timeout=30)
4848
response.raise_for_status()
4949
print('# generated from swift_standards_infopaper_ibanregistry_1.txt,')
5050
print('# downloaded from %s' % download_url)

update/imsi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_mncs_from_wikipedia():
155155
for page in wikipedia_pages:
156156
url = 'https://en.wikipedia.org/w/index.php?title=%s&action=raw' % (
157157
page.replace(' ', '_'))
158-
response = requests.get(url)
158+
response = requests.get(url, timeout=30)
159159
response.raise_for_status()
160160
country = cc = ''
161161
for line in response.iter_lines(decode_unicode=True):

update/isbn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def wrap(text):
5656
if __name__ == '__main__':
5757
print('# generated from RangeMessage.xml, downloaded from')
5858
print('# %s' % download_url)
59-
response = requests.get(download_url)
59+
response = requests.get(download_url, timeout=30)
6060
response.raise_for_status()
6161

6262
# parse XML document

update/isil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def clean(td):
4242

4343

4444
if __name__ == '__main__':
45-
response = requests.get(download_url)
45+
response = requests.get(download_url, timeout=30)
4646
response.raise_for_status()
4747
print('# generated from ISIL Registration Authority, downloaded from')
4848
print('# %s' % download_url)

update/my_bp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ def parse(content):
6666
}
6767
results = defaultdict(lambda: defaultdict(set))
6868
# read the states
69-
response = requests.get(state_list_url, headers=headers, verify='update/my_bp.crt')
69+
response = requests.get(state_list_url, headers=headers, verify='update/my_bp.crt', timeout=30)
7070
response.raise_for_status()
7171
for state, bps in parse(response.content):
7272
for bp in bps.split(','):
7373
results[bp.strip()]['state'] = state
7474
results[bp.strip()]['countries'].add('Malaysia')
7575
# read the countries
76-
response = requests.get(country_list_url, headers=headers, verify='update/my_bp.crt')
76+
response = requests.get(country_list_url, headers=headers, verify='update/my_bp.crt', timeout=30)
7777
response.raise_for_status()
7878
for country, bp in parse(response.content):
7979
results[bp]['countries'].add(country)

update/nz_banks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def branch_list(branches):
7171

7272
if __name__ == '__main__':
7373
# parse the download as an XLS
74-
response = requests.get(download_url)
74+
response = requests.get(download_url, timeout=30)
7575
response.raise_for_status()
7676
content_disposition = response.headers.get('content-disposition', '')
7777
filename = re.findall(r'filename=?(.+)"?', content_disposition)[0].strip('"&# 88C1 39;)

update/oui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
def download_csv(url):
4242
"""Download the list from the site and provide assignment and
4343
organisation names."""
44-
response = requests.get(url)
44+
response = requests.get(url, timeout=30)
4545
response.raise_for_status()
4646
for row in csv.DictReader(line.decode('utf-8') for line in response.iter_lines()):
4747
o = row['Organization Name'].strip().replace('"', '%')

0 commit comments

Comments
 (0)
0