阿里云文档中心的python版本aliyun-python-sdk-rds不支持python3处理

问题:默认情况下文档中心的python版本只支持python2,不兼容python3版本

需要稍微修改源码即可

修改核心sdk包中文件aliyunsdkcore/profile/location_service.py第143行即可

修改方法

    def find_product_domain_from_location_service(
self, region_id, service_code, endpoint_type): request = DescribeEndpointRequest(self.__service_product_name,
self.__service_version,
self.__service_action,
region_id,
service_code,
endpoint_type)
try:
content = request.get_content()
method = request.get_method() signer = getattr(self.__clinetRef, '_signer')
header, url = signer.sign(self.__service_region, request)
if self.__clinetRef.get_user_agent() is not None:
header['User-Agent'] = self.__clinetRef.get_user_agent()
header['x-sdk-client'] = 'python/2.0.0'
protocol = request.get_protocol_type()
response = HttpResponse(
self.__service_domain,
url,
method,
{} if header is None else header,
protocol,
content,
self.__clinetRef.get_port()) status, header, body = response.get_response_object() result = json.loads(body)
if status == 200:
endpoint = result.get('Endpoints').get('Endpoint')
if len(endpoint) <= 0:
return None
else:
return endpoint[0].get('Endpoint')
elif 400 <= status < 500:
# print "serviceCode=" + service_code + " get location error!
# code=" + result.get('Code') +", message =" +
# result.get('Message')
return None
elif status >= 500:
raise exs.ServerException(
result.get('Code'), result.get('Message'))
else:
raise exs.ClientException(
result.get('Code'), result.get('Message'))
except IOError:
raise exs.ClientException(
error_code.SDK_SERVER_UNREACHABLE,
error_msg.get_msg('SDK_SERVER_UNREACHABLE'))
except AttributeError:
raise exs.ClientException(
error_code.SDK_INVALID_REQUEST,
error_msg.get_msg('SDK_INVALID_REQUEST'))

源方法

修改后

    def find_product_domain_from_location_service(
self, region_id, service_code, endpoint_type): request = DescribeEndpointRequest(self.__service_product_name,
self.__service_version,
self.__service_action,
region_id,
service_code,
endpoint_type)
try:
content = request.get_content()
method = request.get_method() signer = getattr(self.__clinetRef, '_signer')
header, url = signer.sign(self.__service_region, request)
if self.__clinetRef.get_user_agent() is not None:
header['User-Agent'] = self.__clinetRef.get_user_agent()
header['x-sdk-client'] = 'python/2.0.0'
protocol = request.get_protocol_type()
response = HttpResponse(
self.__service_domain,
url,
method,
{} if header is None else header,
protocol,
content,
self.__clinetRef.get_port()) status, header, body = response.get_response_object() result = json.loads(body.decode('utf-8'))
# 修改上面行内容
if status == 200:
endpoint = result.get('Endpoints').get('Endpoint')
if len(endpoint) <= 0:
return None
else:
return endpoint[0].get('Endpoint')
elif 400 <= status < 500:
# print "serviceCode=" + service_code + " get location error!
# code=" + result.get('Code') +", message =" +
# result.get('Message')
return None
elif status >= 500:
raise exs.ServerException(
result.get('Code'), result.get('Message'))
else:
raise exs.ClientException(
result.get('Code'), result.get('Message'))
except IOError:
raise exs.ClientException(
error_code.SDK_SERVER_UNREACHABLE,
error_msg.get_msg('SDK_SERVER_UNREACHABLE'))
except AttributeError:
raise exs.ClientException(
error_code.SDK_INVALID_REQUEST,
error_msg.get_msg('SDK_INVALID_REQUEST'))

修改后

json在loads转为对象的时候loads方法的参数需要为字符串格式,而request请求返回的response对象是bytes格式,故需要做下decode。

04-25 22:19