question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

401 Client Error: Unauthorized for url: ...

See original GitHub issue

I’m trying to retrieve a dataset from a Google Collab notebook, unsuccessfully so far, although I did apply all instructions.

import cdsapi

uploaded = files.upload() #to upload the .cdsapirc
!cp .cdsapirc ../root/

c = cdsapi.Client()

c.retrieve(
    'insitu-glaciers-elevation-mass',
    {
        'product_type': [
            'elevation_change', 'mass_balance',
        ],
        'file_version': '20181103',
        'variable': 'all',
        'format': 'zip',
    },
    'download.zip')

insitu_glaciers_elevation_mass = pd.read_csv('download.zip', compression='zip')

This yields the following error:

2020-04-15 13:18:23,712 INFO Welcome to the CDS
2020-04-15 13:18:23,713 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/insitu-glaciers-elevation-mass
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/cdsapi/api.py in _api(self, url, request, method)
    388         try:
--> 389             result.raise_for_status()
    390             reply = result.json()

3 frames
/usr/local/lib/python3.6/dist-packages/requests/models.py in raise_for_status(self)
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 

HTTPError: 401 Client Error: Unauthorized for url: https://cds.climate.copernicus.eu/api/v2/resources/insitu-glaciers-elevation-mass

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-12-ceb78a244bb3> in <module>()
     16         'format': 'zip',
     17     },
---> 18     'download.zip')
     19 
     20 insitu_glaciers_elevation_mass = pd.read_csv('download.zip', compression='zip')

/usr/local/lib/python3.6/dist-packages/cdsapi/api.py in retrieve(self, name, request, target)
    315 
    316     def retrieve(self, name, request, target=None):
--> 317         result = self._api('%s/resources/%s' % (self.url, name), request, 'POST')
    318         if target is not None:
    319             result.download(target)

/usr/local/lib/python3.6/dist-packages/cdsapi/api.py in _api(self, url, request, method)
    408                                  "of '%s' at %s" % (t['title'], t['url']))
    409                     error = '. '.join(e)
--> 410                 raise Exception(error)
    411             else:
    412                 raise

Exception: <html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>

I did first accept the terms & conditions: Imgur

What am I missing?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

16reactions
patel-zeelcommented, Aug 6, 2020

Before I was having the following settings in my $HOME/.cdsapirc url: https://cds.climate.copernicus.eu/api/v2 key: {xxxxx}:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

After getting this error I changed to the following (Removal of curly brackets) and error got resolved. url: https://cds.climate.copernicus.eu/api/v2 key: xxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

1reaction
ZSSAPRcommented, May 13, 2022

try to delete the blank after the colon between your UID and API key

Read more comments on GitHub >

github_iconTop Results From Across the Web

401 Client Error: Unauthorized for url - python - Stack Overflow
It means you are sending wrong credentials please verify your credentials. – kvk30. Jan 29, 2018 at 9:57. 1.
Read more >
How to Fix a 401 Unauthorized Error? - GeeksforGeeks
The 401 Unauthorized Error is an HTTP status code error that represented the request sent by the client to the server that lacks...
Read more >
401 Unauthorized - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed ...
Read more >
401 Unauthorized Error: What It Is and How to Fix It
The most common cause of a 401 Unauthorized Error is an incorrect URL. As discussed before, web servers will disallow access to improper...
Read more >
Error 401 Client Error: Unauthorized for url - Hub
Hi @talids, you're getting a 401 error because you're not authenticated when making the request, and either: the model doesn't exist; the model ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found