zoukankan      html  css  js  c++  java
  • 阿里云 rds python sdk不支持python3处理

    阿里云文档中心的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。

  • 相关阅读:
    微信小程序promise解决onload异步
    小程序中使用 Less (VScode)
    Vue中使用less
    小程序获取 图片宽高
    ssh 登录出现Are you sure you want to continue connecting (yes/no)?解决方法
    SQL SERVER 收缩日志
    SQL SERVER-日期时间
    oracle判断查询结果是否为空
    修改Tomcat默认JDK版本
    Microsoft SQL Server Management Studio ------- 附加数据库 对于 服务器“xxx&amp;amp;quot;失败(错误码5120)
  • 原文地址:https://www.cnblogs.com/aslongas/p/7649503.html
Copyright © 2011-2022 走看看