lucadelu / pyModis

python library to work with MODIS data
http://www.pymodis.org/
Other
165 stars 84 forks source link

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

Open MolettoLobos opened 5 years ago

MolettoLobos commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

misiut commented 5 years ago

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 commented 4 years ago

Hi @lokendrarathore ,

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

MarcoHannemann commented 2 years ago

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 commented 2 years ago

@MarcoHannemann could you provide a Pull request?

baiyissp112 commented 1 year ago

how to disable cert checking?

lucadelu commented 1 year ago

@baiyissp112 please try newer version with token support

rcammi commented 1 year ago

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 commented 1 year ago

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

rcammi commented 1 year ago

@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 https://github.com/lucadelu/pyModis/issues/59 instructions but still getting the same error. I'm on python3, tried it in windows 10 and linux mint.

rcammi commented 1 year ago

@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.