Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #78 from HumanSignal/fb-LEAP-938
Browse files Browse the repository at this point in the history
fix: LEAP-938: Fix user-agent header when downloading files
  • Loading branch information
niklub committed Apr 10, 2024
2 parents f472671 + 3cf9b50 commit 4564303
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions label_studio_tools/core/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ def download_and_cache(
if not os.path.exists(filepath):
logger.info('Download {url} to {filepath}'.format(url=url, filepath=filepath))
if download_resources:
headers = {
# avoid requests.exceptions.HTTPError: 403 Client Error: Forbidden. Please comply with the User-Agent policy:
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'
}
# check if url matches hostname - then uses access token to this Label Studio instance
if access_token and hostname and parsed_url.netloc == urlparse(hostname).netloc:
headers = {'Authorization': 'Token ' + access_token}
headers['Authorization'] = 'Token ' + access_token
logger.debug('Authorization token is used for download_and_cache')
else:
headers = {}
r = requests.get(url, stream=True, headers=headers)
r.raise_for_status()
with io.open(filepath, mode='wb') as fout:
Expand Down

0 comments on commit 4564303

Please sign in to comment.