Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'URLError' object has no attribute 'code' #123

Open
MolettoLobos opened this issue Jul 16, 2019 · 12 comments
Open

AttributeError: 'URLError' object has no attribute 'code' #123

MolettoLobos opened this issue Jul 16, 2019 · 12 comments

Comments

@MolettoLobos
Copy link

MolettoLobos commented Jul 16, 2019

i'm trying to download the MODIS LST product version 6

today = date.today()

End = today.strftime('%Y-%m-%d')
Start = '2005-01-01'
Start2 = '2005-01-01'
#personal data
user = "****"
password = "****"
#url
url="https://e4ftl01.cr.usgs.gov/"
#destiny
dest = "E:\Data\MOD11A1"
#product
product = "MOD11A1.006"
#tiles a descargar
tiles = "h12v13"
#start
start = Start2 
end = End 
delta = 1

modisDown = downmodis.downModis(destinationFolder=dest,password=password,user=user,url=url,product=product,tiles=tiles,
                                today=start,enddate=end,delta=delta)
modisDown.connect()
`modisDown.downloadsAllDay()

but when i apply the code shows the following error:

File "E:/GeoPrads/Scripts/Python/GeoPrads_whole_period.py", line 60, in <module>
    modisDown.downloadsAllDay()

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymodis\downmodis.py", line 849, in downloadsAllDay
    self._downloadAllDaysHTTP(days)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymodis\downmodis.py", line 865, in _downloadAllDaysHTTP
    self.dayDownload(day, listFilesDown)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymodis\downmodis.py", line 827, in dayDownload
    self.downloadFile(i, file_hdf, day)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymodis\downmodis.py", line 676, in downloadFile
    self._downloadFileHTTP(filDown, filHdf, day)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymodis\downmodis.py", line 698, in _downloadFileHTTP
    "error {ex}, reason {re}".format(e.code,

AttributeError: 'URLError' object has no attribute 'code'

why could it be the issue?

Regards

@LSRathore
Copy link

The following is running fine on my system, can you run the script again:

Start = '2005-01-01'
Start2 = '2005-02-01'
#personal data
user = "***"
password = "***"
#url
url="https://e4ftl01.cr.usgs.gov/"
#destiny
dest = "G:\\Rathore\\temp1"
#product
product = "MOD11A1.006"
#tiles a descargar
tiles = "h12v13"
#start

modisDown = downmodis.downModis(destinationFolder=dest,password=password,user=user,url=url,product=product,tiles=tiles,today=Start,enddate=Start2)
modisDown.connect()
modisDown.downloadsAllDay()

@LSRathore
Copy link

Or it might be because you don't have sufficient memory in the drive.

@misiut
Copy link

misiut commented Aug 20, 2019

I think it's caused by previous errors raised by urllib. In my case it was certificate error (also authorization error). When I disable cert checking its working fine. Apparently pyModis doesn't understand them, hence missing attribute error.

@lucadelu
Copy link
Owner

Hi @lokendrarathore ,

sorry for delay, I'm not able to reproduce the error. Are you still having this problem?

@MarcoHannemann
Copy link

I just ran into this error. @misiut is right with their assumption about the urllib library. pyModis can't handle the following error:
urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>

The attributeError is raised because e.code() cannot be called on urllib.error.URLError according to the docs.

The problem lies here in downmodis.py:
logging.warning("Tried to downlaod with urllib but got this " "error {co}, reason {re}".format(co=e.code, re=e.reason))

I guess the URLError needs to be catched seperately.

@lucadelu
Copy link
Owner

lucadelu commented Feb 4, 2022

@MarcoHannemann could you provide a Pull request?

@baiyissp112
Copy link

how to disable cert checking?

@lucadelu
Copy link
Owner

@baiyissp112 please try newer version with token support

@rcammi
Copy link

rcammi commented Oct 5, 2022

Hi, I just ran into this error while trying to run script in a server. Locally it's working fine. Is there a solution to the problem? I'm on last pyModis version (2.3.0)

@lucadelu
Copy link
Owner

lucadelu commented Oct 6, 2022

@rcammi could you retry today? because usually on Wednesday the NASA reboot their own server

@rcammi
Copy link

rcammi commented Oct 11, 2022

@lucadelu tried again, and now i'm getting and authorization error (401) locally and on server which leads to AttributeError: 'KeyError' object has no attribute 'code'. It's weird because locally it seemed to be working before I reported the error.

This is the script i'm running:

tiles = [
    "h11v10",
    "h12v10",
]

modis_obj = pymodis.downmodis.downModis(
    "./downloads",
    url="https://e4ftl01.cr.usgs.gov/",
    user=user,
    password=passwd,
    tiles=tiles,
    path="MOLT",
    product="MOD13A3.061",
    today=f"2020-12-31",  # the day to start downloading; in order to pass a date different from today use the format YYYY-MM-DD
    enddate=f"2020-01-01",  # the day to end downloading; in order to pass a date use the format YYYY-MM-DD. This day must be before the ‘today’ parameter. Downloading happens in reverse order (currently)
    debug=True,
)  # for parameters info check http://www.pymodis.org/pymodis/downmodis.html#pymodis.downmodis.downModis

modis_obj.connect()
print(modis_obj.getListDays())

modis_obj.downloadsAllDay()  # allDays=True

Log error:

2022-10-11 10:36:52,052 - DEBUG - The number of days to download is: 12
2022-10-11 10:36:52,052 - DEBUG - The url is: https://e4ftl01.cr.usgs.gov/MOLT/MOD13A3.061/2020.12.01
2022-10-11 10:36:52,053 - DEBUG - Starting new HTTPS connection (1): e4ftl01.cr.usgs.gov:443
2022-10-11 10:36:53,911 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01 HTTP/1.1" 301 264
2022-10-11 10:36:53,912 - DEBUG - Resetting dropped connection: e4ftl01.cr.usgs.gov
2022-10-11 10:36:56,489 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01/ HTTP/1.1" 200 None
2022-10-11 10:37:04,136 - DEBUG - The number of file to download is: 4
2022-10-11 10:37:06,204 - WARNING - Tried to downlaod with urllib but got this error 401, reason Unauthorized
2022-10-11 10:37:06,205 - DEBUG - Starting new HTTPS connection (1): e4ftl01.cr.usgs.gov:443
2022-10-11 10:37:07,845 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01/MOD13A3.A2020336.h12v10.061.2021012023907.hdf HTTP/1.1" 302 522
2022-10-11 10:37:07,846 - DEBUG - Starting new HTTPS connection (1): urs.earthdata.nasa.gov:443
2022-10-11 10:37:10,542 - DEBUG - https://urs.earthdata.nasa.gov:443 "GET /oauth/authorize?scope=uid&app_type=401&client_id=ijpRZvb9qeKCK5ctsn75Tg&response_type=code&redirect_uri=https%3A%2F%2Fe4ftl01.cr.usgs.gov%2Foauth&state=aHR0cHM6Ly9lNGZ0bDAxLmNyLnVzZ3MuZ292L01PTFQvTU9EMTNBMy4wNjEvMjAyMC4xMi4wMS9NT0QxM0EzLkEyMDIwMzM2LmgxMnYxMC4wNjEuMjAyMTAxMjAyMzkwNy5oZGY HTTP/1.1" 401 None

I followed #59 instructions but still getting the same error. I'm on python3, tried it in windows 10 and linux mint.

@rcammi
Copy link

rcammi commented Oct 12, 2022

@lucadelu tried again, and now i'm getting and authorization error (401) locally and on server which leads to AttributeError: 'KeyError' object has no attribute 'code'. It's weird because locally it seemed to be working before I reported the error.

This is the script i'm running:

tiles = [
    "h11v10",
    "h12v10",
]

modis_obj = pymodis.downmodis.downModis(
    "./downloads",
    url="https://e4ftl01.cr.usgs.gov/",
    user=user,
    password=passwd,
    tiles=tiles,
    path="MOLT",
    product="MOD13A3.061",
    today=f"2020-12-31",  # the day to start downloading; in order to pass a date different from today use the format YYYY-MM-DD
    enddate=f"2020-01-01",  # the day to end downloading; in order to pass a date use the format YYYY-MM-DD. This day must be before the ‘today’ parameter. Downloading happens in reverse order (currently)
    debug=True,
)  # for parameters info check http://www.pymodis.org/pymodis/downmodis.html#pymodis.downmodis.downModis

modis_obj.connect()
print(modis_obj.getListDays())

modis_obj.downloadsAllDay()  # allDays=True

Log error:

2022-10-11 10:36:52,052 - DEBUG - The number of days to download is: 12 2022-10-11 10:36:52,052 - DEBUG - The url is: https://e4ftl01.cr.usgs.gov/MOLT/MOD13A3.061/2020.12.01 2022-10-11 10:36:52,053 - DEBUG - Starting new HTTPS connection (1): e4ftl01.cr.usgs.gov:443 2022-10-11 10:36:53,911 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01 HTTP/1.1" 301 264 2022-10-11 10:36:53,912 - DEBUG - Resetting dropped connection: e4ftl01.cr.usgs.gov 2022-10-11 10:36:56,489 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01/ HTTP/1.1" 200 None 2022-10-11 10:37:04,136 - DEBUG - The number of file to download is: 4 2022-10-11 10:37:06,204 - WARNING - Tried to downlaod with urllib but got this error 401, reason Unauthorized 2022-10-11 10:37:06,205 - DEBUG - Starting new HTTPS connection (1): e4ftl01.cr.usgs.gov:443 2022-10-11 10:37:07,845 - DEBUG - https://e4ftl01.cr.usgs.gov:443 "GET /MOLT/MOD13A3.061/2020.12.01/MOD13A3.A2020336.h12v10.061.2021012023907.hdf HTTP/1.1" 302 522 2022-10-11 10:37:07,846 - DEBUG - Starting new HTTPS connection (1): urs.earthdata.nasa.gov:443 2022-10-11 10:37:10,542 - DEBUG - https://urs.earthdata.nasa.gov:443 "GET /oauth/authorize?scope=uid&app_type=401&client_id=ijpRZvb9qeKCK5ctsn75Tg&response_type=code&redirect_uri=https%3A%2F%2Fe4ftl01.cr.usgs.gov%2Foauth&state=aHR0cHM6Ly9lNGZ0bDAxLmNyLnVzZ3MuZ292L01PTFQvTU9EMTNBMy4wNjEvMjAyMC4xMi4wMS9NT0QxM0EzLkEyMDIwMzM2LmgxMnYxMC4wNjEuMjAyMTAxMjAyMzkwNy5oZGY HTTP/1.1" 401 None

I followed #59 instructions but still getting the same error. I'm on python3, tried it in windows 10 and linux mint.

Problem solved with new version of pymodis (2.4.0) and new token auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants