Django连接Odoo XMLRPC时出错



我无法以任何方式与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

问题可能出在哪里?

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

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

最新更新