11#!/usr/bin/env python
2- # -*- coding: utf-8 -*-
32#
43# Copyright (c) nexB Inc. and others. All rights reserved.
54# ScanCode is a trademark of nexB Inc.
2524
2625DEJACODE_API_URL_PACKAGES = f"{ DEJACODE_API_URL } packages/"
2726DEJACODE_API_HEADERS = {
28- "Authorization" : "Token {}" . format ( DEJACODE_API_KEY ) ,
27+ "Authorization" : f "Token { DEJACODE_API_KEY } " ,
2928 "Accept" : "application/json; indent=4" ,
3029}
3130
@@ -50,6 +49,7 @@ def fetch_dejacode_packages(params):
5049 DEJACODE_API_URL_PACKAGES ,
5150 params = params ,
5251 headers = DEJACODE_API_HEADERS ,
52+ timeout = 10 ,
5353 )
5454
5555 return response .json ()["results" ]
@@ -93,7 +93,7 @@ def update_with_dejacode_about_data(distribution):
9393 if package_data :
9494 package_api_url = package_data ["api_url" ]
9595 about_url = f"{ package_api_url } about"
96- response = requests .get (about_url , headers = DEJACODE_API_HEADERS )
96+ response = requests .get (about_url , headers = DEJACODE_API_HEADERS , timeout = 10 )
9797 # note that this is YAML-formatted
9898 about_text = response .json ()["about_data" ]
9999 about_data = saneyaml .load (about_text )
@@ -113,7 +113,7 @@ def fetch_and_save_about_files(distribution, dest_dir="thirdparty"):
113113 if package_data :
114114 package_api_url = package_data ["api_url" ]
115115 about_url = f"{ package_api_url } about_files"
116- response = requests .get (about_url , headers = DEJACODE_API_HEADERS )
116+ response = requests .get (about_url , headers = DEJACODE_API_HEADERS , timeout = 10 )
117117 about_zip = response .content
118118 with io .BytesIO (about_zip ) as zf :
119119 with zipfile .ZipFile (zf ) as zi :
@@ -201,6 +201,7 @@ def create_dejacode_package(distribution):
201201 DEJACODE_API_URL_PACKAGES ,
202202 data = new_package_payload ,
203203 headers = DEJACODE_API_HEADERS ,
204+ timeout = 10 ,
204205 )
205206 new_package_data = response .json ()
206207 if response .status_code != 201 :
0 commit comments