agrenott / pyhgtmap

Generate OSM contour lines from NASA SRTM (or other digital elevation model sources) data
GNU General Public License v2.0
13 stars 3 forks source link

SONN source: Token has been expired or revoked #40

Closed keenonkites closed 11 months ago

keenonkites commented 11 months ago

Hi, allthough I didn't try it with the very latest sources looking at the commits I assume the following problem exists also in the last commit:

I've tried to create contours from SONNY1 today and ran into following error message:


N54E005: trying sonn1 ...
    self.check_cached_file(file_name, resolution)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/sources/__init__.py", line 49, in check_cached_file
    found_size: int = os.path.getsize(file_name)
  File "/usr/lib/python3.8/genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: './hgt/SONN1/N54E005.hgt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pydrive2/auth.py", line 673, in Refresh
    self.credentials.refresh(self.http)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/oauth2client/client.py", line 545, in refresh
    self._refresh(http)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/oauth2client/client.py", line 761, in _refresh
    self._do_refresh_request(http)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/oauth2client/client.py", line 819, in _do_refresh_request
    raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Token has been expired or revoked.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/XYZ/venv_pyhgtmap/bin/pyhgtmap", line 8, in <module>
    sys.exit(main())
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/main.py", line 593, in main
    main_internal(sys.argv[1:])
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/main.py", line 574, in main_internal
    hgtDataFiles = NASASRTMUtil.getFiles(
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/NASASRTMUtil.py", line 915, in getFiles
    saveFilename = sources_pool.get_file(opener, area, source)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/NASASRTMUtil.py", line 886, in get_file
    file_name = self._real_pool.get_source("sonn").get_file(
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/sources/__init__.py", line 77, in get_file
    self.download_missing_file(area, resolution, file_name)
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/sources/sonny.py", line 75, in download_missing_file
    files: List[GoogleDriveFile] = self.gdrive.ListFile(
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pyhgtmap/sources/sonny.py", line 61, in gdrive
    gauth.CommandLineAuth()
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pydrive2/auth.py", line 131, in _decorated
    self.Refresh()
  File "/home/XYZ/venv_pyhgtmap/lib/python3.8/site-packages/pydrive2/auth.py", line 675, in Refresh
    raise RefreshError("Access token refresh failed: %s" % error)
pydrive2.auth.RefreshError: Access token refresh failed: invalid_grant: Token has been expired or revoked.

``

I think that's probably normal, but I hat do delete .pyhgtmap/gdrive-credentials.json manually to get it requesting a new Code and running again. Not sure if this is the intention, but it probably could be handled bit more user friendly and (re)move the old credentials file automatically and request new authorisation.

Cheers
Patrik
agrenott commented 11 months ago

Seems related to https://github.com/iterative/PyDrive2/issues/184. Indeed, catching the exception and deleting the file to retry full auth flow should do the trick.

keenonkites commented 11 months ago

Thanks for fixing it.... as I'll be using pyhgtmap quite intensively in the near future I'm sure I'll be running into an expired token again... I will let you know.

Cheers Patrik

keenonkites commented 11 months ago

Confirmation: ran into expired token today and renewal worked properly.

Thanks again. Cheers Patrik