与odoo xmlrpc连接时的Django错误

时间:2018-08-26 01:12:21

标签: python django python-3.x odoo xmlrpclib

我无法以任何方式连接odoo,这就是我正在做的事情:

view.py

class UserSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'

class ProxiedTransport(Transport):

    def set_proxy(self, host, port=None, headers=None):
        self.proxy = host, port
        self.proxy_headers = headers

    def make_connection(self, host):
        connection = http.client.HTTPConnection(*self.proxy)
        connection.set_tunnel(host, headers=self.proxy_headers)
        self._connection = host, connection
        return connection

class ResUser(ViewSet):
    url = 'http://localhost'
    db = 'odoo8'
    username = 'admin'
    password = 'admin'

    def list(self,request,format=None):
        p = ProxiedTransport()
        p.set_proxy('proxy.server',8080)
        common = ServerProxy('{}/xmlrpc/2/common'.format(self.url),p)
        uid = common.authenticate(self.db,self.username,self.password,{})

        return Response({})

但是他给我丢了一个错误:

Request Method:     GET 
Request URL:    http://localhost:8000/odoo-api/res/
Django Version:     2.1 
Exception Type:     gaierror 
Exception Value:    [Errno -2] Name or service not known
Exception Location:     /usr/lib/python3.6/socket.py in getaddrinfo, line 745

哪里出问题了?

1 个答案:

答案 0 :(得分:0)

url 变量中,您需要添加端口号以及列符号以获取更多信息,请在python中检查以下示例。

https://freeweblearns.blogspot.com/2018/11/how-to-use-xmlrpc-using-python-for-new.html