Django:在 Traceback 中找不到异常
Posted
技术标签:
【中文标题】Django:在 Traceback 中找不到异常【英文标题】:Django: Could not found exception in Traceback 【发布时间】:2022-01-12 15:39:55 【问题描述】:我在 Django 项目中遇到了一些关于 python 请求的问题。它只发生在第二个 requests.post() 中。
虽然它以异常 TypeError: getresponse() got an unexpected keyword argument 'buffering'
退出。
但是在更新 urllib3. traceback 也不例外。
[2021-12-08 15:54:48 +0000] [11410] [CRITICAL] WORKER TIMEOUT (pid:11439)
Traceback (most recent call last):
File "/home/ubuntu/projects/project/api/views/a_view.py", line 765, in create_power_trace
headers=power_trace_headers)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/lib/python3.7/http/client.py", line 1373, in getresponse
response.begin()
File "/usr/local/lib/python3.7/http/client.py", line 319, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.7/http/client.py", line 280, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/home/ubuntu/projects/venv/lib/python3.7/site-packages/gunicorn/workers/base.py", line 201, in handle_abort
sys.exit(1)
SystemExit: 1
供您参考,我的代码是这样的:-
res1 = requests.post(url1, data=data1)
result = res1.json()
print(result['id']) # successfully prints
data2 = 'id': result['id']
res2 = requests.post(url2, data=data2) # System exited
print(res2)
上面的 sn-p 在我的项目之外工作正常(在具有相同环境相同实例的不同脚本中测试)。 当然,在本地没有发现任何问题。
【问题讨论】:
这个 sn-p 应该花很长时间吗?我怀疑您的 Gunicorn 超时并直接退出(在这种情况下,它不会显示与 HTTP 相关的异常) 请出示minimal reproducible example。 @jkoestinger。谢谢。你是对的。 nginx 配置有问题。现在在nginx conf中添加server_name后它正在工作 【参考方案1】:其实问题不是由 python 或 django 引起的。
请求因 Nginx 配置错误而丢失。我认为我的请求已到达目的地,但由于我忘记在 nginx conf 中添加 server_name,因此响应无法返回源。
【讨论】:
正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。以上是关于Django:在 Traceback 中找不到异常的主要内容,如果未能解决你的问题,请参考以下文章