I keep getting this error:
我一直收到这样的错误:
HTTPConnectionPool(host='localhost', port=18069): Max retries exceeded with url: /web/session/authenticate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe5e33f0220>: Failed to establish a new connection: [Errno 111] Connection refused'))
I searched through StackOverflow and couldn't find the solution to help me.
我在StackOverflow中搜索,但找不到解决方案来帮助我。
Here's my code example:
以下是我的代码示例:
class CustomController(http.Controller):
@http.route('/api/custom_auth/login', type='json', auth='public', methods=['POST'])
def authenticate_user(self):
data = json.loads(request.httprequest.data)
base_url = data['base_url']
if not base_url:
base_url = 'http://localhost:8069'
authenticate_url = f"{base_url}/web/session/authenticate"
login_data = {
"jsonrpc": "2.0",
"params": {
"db": data['db_name'],
"login": data['username'],
"password": data['password']
}
}
try:
response = requests.post(authenticate_url, json=login_data)
if response.status_code == 200 and response.json().get('result'):
cookie_id = response.headers.get('Set-Cookie').split('; ')[0]
return cookie_id
else:
print("Authentication failed")
return None
except requests.exceptions.RequestException as e:
print(f"Error: {str(e)}")
return None
Basically, I'm trying to write an API to get Set-Cookie in odoo, however, I keep getting the above error. (I still can call to /web/session/authenticate)
AND
I use docker.
基本上,我正在尝试编写一个API来在Odoo中获取Set-Cookie,然而,我一直收到上面的错误。(我仍然可以调用/web/会话/身份验证),并且我使用docker。
更多回答
Your port 18069
must be not listening for connections. Check if the port is open and is able to receive new connection requests.
您的端口18069一定没有侦听连接。检查端口是否已打开并能够接收新的连接请求。
优秀答案推荐
我是一名优秀的程序员,十分优秀!