python|GEE python本地环境配置"[WinError 10060]"错误解决方案

title: GEE python本地环境配置"[WinError 10060]"错误
date: 2018-12-10
categories: GEE
tags: python
WinError10060错误
首先参考GEE官方文档进行GEE的Python环境配置
由于某些众所周知的原因,访问GEE云端需要设置网络代理,但是有些时候会发现设置全局代理后仍然不能正常运行

# Import the Earth Engine Python Packageimport ee# Initialize the Earth Engine object, using the authentication credentials.ee.Initialize()# Print the information for an image asset.image = ee.Image('srtm90_v4')print(image.getInfo())

运行至ee.Initialize()出现以下错误:
Exception has occurred: TimeoutError
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
解决方案:
# Import the Earth Engine Python Package import ee import os # update the proxy settings # os.environ['HTTP_PROXY'] = 'my_proxy_id:proxy_port' # os.environ['HTTPS_PROXY'] = 'my_proxy_id:proxy_port' os.environ['HTTP_PROXY'] = 'http://127.0.0.1:1080' os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:1080'# Initialize the Earth Engine object, using the authentication credentials. ee.Initialize()# Print the information for an image asset. image = ee.Image('srtm90_v4') print(image.getInfo())

需要在代码中设置网络代理地址及端口
e.g. 如果代理地址为 http://127.0.0.1:1080,则需要添加下面两行代码
os.environ[‘HTTP_PROXY’] = ‘http://127.0.0.1:1080’
os.environ[‘HTTPS_PROXY’] = ‘http://127.0.0.1:1080’
根据自己电脑的代理方式进行设置
代码正常运行输出图像信息如下:
【python|GEE python本地环境配置"[WinError 10060]"错误解决方案】{'type': 'Image', 'bands': [{'id': 'elevation', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': -32768, 'max': 32767}, 'dimensions': [432000, 144000], 'crs': 'EPSG:4326', 'crs_transform': [0.000833333333333, 0.0, -180.0, 0.0, -0.000833333333333, 60.0]}], 'version': 1494271934303000, 'id': 'srtm90_v4', 'properties': {'system:time_start': 950227200000, 'system:time_end': 951177600000, 'system:asset_size': 18827626666}}

    推荐阅读