gee-community/geemap

geemap.ee_export_image() report "An error occurred while downloading."

Closed this issue · 6 comments

Environment Information

windows11 , python==3.8.8 , geemap==0.19.0

# Normal operation
geemap.ee_export_image(
               s2_sr_cld_col.median().select(['B1','B2','B3','B4','B5']),
               filename=filename,
               scale=10, region=AOI, file_per_band=True,timeout=500)
geemap.ee_export_image(
               s2_sr_cld_col.first().select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A']),
               filename=filename,
               scale=10, region=AOI, file_per_band=True,timeout=500)

# !!An error occurred!!
geemap.ee_export_image(
               s2_sr_cld_col.median().select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A']),
               filename=filename,
               scale=10, region=AOI, file_per_band=True,timeout=500)

Description

I encountered a strange problem when using the xxx function. I tried to test it in different ways to find out if I was using it improperly. I found that the error was related to the size of the image, but the image itself was not very large. This error occurs when median/max/min etc. reducers are used.

Here is the message that reports the error

Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/2ead3b479203b02d1d3de61ce8459dcb-4952ef6c7a5bca893df8ca31e8f41cc0:getPixels
Please wait ...
An error occurred while downloading.
---------------------------------------------------------------------------
RemoteDisconnected                        Traceback (most recent call last)
File D:\Code_base\anaconda\envs\GEE\lib\site-packages\urllib3\connectionpool.py:670, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    669 # Make the request on the httplib connection object.
--> 670 httplib_response = self._make_request(
    671     conn,
    672     method,
    673     url,
    674     timeout=timeout_obj,
    675     body=body,
    676     headers=headers,
    677     chunked=chunked,
    678 )
    680 # If we're going to release the connection in ``finally:``, then
    681 # the response doesn't need to know about the connection. Otherwise
    682 # it will also try to release it and we'll have a double-release
    683 # mess.

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\urllib3\connectionpool.py:426, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    422         except BaseException as e:
    423             # Remove the TypeError from the exception chain in
    424             # Python 3 (including for exceptions like SystemExit).
    425             # Otherwise it looks like a bug in the code.
--> 426             six.raise_from(e, None)
    427 except (SocketTimeout, BaseSSLError, SocketError) as e:

File <string>:3, in raise_from(value, from_value)

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\urllib3\connectionpool.py:421, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    420 try:
--> 421     httplib_response = conn.getresponse()
    422 except BaseException as e:
    423     # Remove the TypeError from the exception chain in
    424     # Python 3 (including for exceptions like SystemExit).
    425     # Otherwise it looks like a bug in the code.

File D:\Code_base\anaconda\envs\GEE\lib\http\client.py:1348, in HTTPConnection.getresponse(self)
   1347 try:
-> 1348     response.begin()
   1349 except ConnectionError:

File D:\Code_base\anaconda\envs\GEE\lib\http\client.py:316, in HTTPResponse.begin(self)
    315 while True:
--> 316     version, status, reason = self._read_status()
    317     if status != CONTINUE:

File D:\Code_base\anaconda\envs\GEE\lib\http\client.py:285, in HTTPResponse._read_status(self)
    282 if not line:
    283     # Presumably, the server closed the connection before
    284     # sending a valid response.
--> 285     raise RemoteDisconnected("Remote end closed connection without"
    286                              " response")
    287 try:

RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\adapters.py:439, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    438 if not chunked:
--> 439     resp = conn.urlopen(
    440         method=request.method,
    441         url=url,
    442         body=request.body,
    443         headers=request.headers,
    444         redirect=False,
    445         assert_same_host=False,
    446         preload_content=False,
    447         decode_content=False,
    448         retries=self.max_retries,
    449         timeout=timeout
    450     )
    452 # Send the request.
    453 else:

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\urllib3\connectionpool.py:726, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    724     e = ProtocolError("Connection aborted.", e)
--> 726 retries = retries.increment(
    727     method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    728 )
    729 retries.sleep()

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\urllib3\util\retry.py:446, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    445 if new_retry.is_exhausted():
--> 446     raise MaxRetryError(_pool, url, error or ResponseError(cause))
    448 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='earthengine.googleapis.com', port=443): Max retries exceeded with url: /v1alpha/projects/earthengine-legacy/thumbnails/2ead3b479203b02d1d3de61ce8459dcb-4952ef6c7a5bca893df8ca31e8f41cc0:getPixels (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))

During handling of the above exception, another exception occurred:

ProxyError                                Traceback (most recent call last)
File D:\Code_base\anaconda\envs\GEE\lib\site-packages\geemap\common.py:2296, in ee_export_image(ee_object, filename, scale, crs, crs_transform, region, dimensions, file_per_band, format, unmask_value, timeout, proxies)
   2295 print(f"Downloading data from {url}\nPlease wait ...")
-> 2296 r = requests.get(url, stream=True, timeout=timeout, proxies=proxies)
   2298 if r.status_code != 200:

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\api.py:76, in get(url, params, **kwargs)
     75 kwargs.setdefault('allow_redirects', True)
---> 76 return request('get', url, params=params, **kwargs)

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\api.py:61, in request(method, url, **kwargs)
     60 with sessions.Session() as session:
---> 61     return session.request(method=method, url=url, **kwargs)

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\sessions.py:530, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    529 send_kwargs.update(settings)
--> 530 resp = self.send(prep, **send_kwargs)
    532 return resp

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\sessions.py:643, in Session.send(self, request, **kwargs)
    642 # Send the request
--> 643 r = adapter.send(request, **kwargs)
    645 # Total elapsed time of the request (approximately)

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\requests\adapters.py:510, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    509 if isinstance(e.reason, _ProxyError):
--> 510     raise ProxyError(e, request=request)
    512 if isinstance(e.reason, _SSLError):
    513     # This branch is for urllib3 v1.22 and later.

ProxyError: HTTPSConnectionPool(host='earthengine.googleapis.com', port=443): Max retries exceeded with url: /v1alpha/projects/earthengine-legacy/thumbnails/2ead3b479203b02d1d3de61ce8459dcb-4952ef6c7a5bca893df8ca31e8f41cc0:getPixels (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))

During handling of the above exception, another exception occurred:

UnboundLocalError                         Traceback (most recent call last)
Cell In [20], line 1
----> 1 geemap.ee_export_image(
      2                s2_sr_cld_col.median().select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A']),
      3                filename=filename,
      4                scale=10, region=AOI, file_per_band=True,timeout=500)

File D:\Code_base\anaconda\envs\GEE\lib\site-packages\geemap\common.py:2308, in ee_export_image(ee_object, filename, scale, crs, crs_transform, region, dimensions, file_per_band, format, unmask_value, timeout, proxies)
   2306 except Exception as e:
   2307     print("An error occurred while downloading.")
-> 2308     print(r.json()["error"]["message"])
   2309     return
   2311 try:

UnboundLocalError: local variable 'r' referenced before assignment

Are you using VPN? The error message shows that it is a connection timeout problem. This is not a geemap problem.

I used VPN and was able to output other images normally, but only the images obtained by the median/max/min method could not be output normally.
In above I mentioned three inputs and outputs, the first two are able to output normally, only the third will have this problem, I also feel very confused

Try Google Colab. I am 100% sure if it is your network problem.

It does work well with Colab, but I'm still confused as to why jupyter can export some of the data, but not the data obtained from median/max/min. Thank you very much and have a nice life!

Solve

I found out that the reason for this is that the image type obtained by median/max/min is double, so converting it to float or int will output it normally. I'm sorry for the disturbance.

Thank you for sharing the solution