Django:超过最大重试次数,网址:/o/token/ [Errno 11001] getaddrinfo 失败
大家好,我正在使用 DJANGO TENANTS 和 DRF 创建一个多租户应用程序,
我正在尝试使用以下函数
登录 api-view
@api_view(['POST'])
@permission_classes([permissions.AllowAny])
def login(request):
restaurant_name = request.POST.get('restaurant_name')
email = request.POST.get('email')
password = request.POST.get('password')
restaurant_schema = restaurant_name
if not restaurant_name:
restaurant_schema = 'public'
domain_name = 'http://localhost:8000/o/token/'
else:
domain_name = 'http://' + restaurant_name + '.localhost:8000/o/token/'
with schema_context(restaurant_schema):
# c = Client.objects.get(name='BFC')
# return Response(c.reverse(request,'test'))
app = Application.objects.first()
r = requests.post(domain_name,
data={
'grant_type': 'password',
'username': email,
'password': password,
'client_id': app.client_id,
# 'scope': 'read',
'client_secret': app.client_secret,
},)
return Response(r.json())
创建登录 api但我'我收到此错误:
HTTPConnectionPool(host='bfc.localhost', port=8000): url: /o/token/ 超出最大重试次数(由 NewConnectionError('
: 无法建立新连接:[Errno 11001] getaddrinfo失败'))
我有尝试使用以下命令检查连接:
socket.create_connection(('localhost',8000),timeout=2)
bfc.localhost
socket.create_connection(('bfc.localhost',8000),timeout=2)
无法创建连接,但 localhost 我也可以从浏览器访问域
附加信息:
在 Postman OAuth 2 部分中,我可以获得具有相同字段的响应
Hey guys I'm creating a multi-tenant app using DJANGO TENANTS and DRF
I'm trying to create a login api using the following function
login api-view
@api_view(['POST'])
@permission_classes([permissions.AllowAny])
def login(request):
restaurant_name = request.POST.get('restaurant_name')
email = request.POST.get('email')
password = request.POST.get('password')
restaurant_schema = restaurant_name
if not restaurant_name:
restaurant_schema = 'public'
domain_name = 'http://localhost:8000/o/token/'
else:
domain_name = 'http://' + restaurant_name + '.localhost:8000/o/token/'
with schema_context(restaurant_schema):
# c = Client.objects.get(name='BFC')
# return Response(c.reverse(request,'test'))
app = Application.objects.first()
r = requests.post(domain_name,
data={
'grant_type': 'password',
'username': email,
'password': password,
'client_id': app.client_id,
# 'scope': 'read',
'client_secret': app.client_secret,
},)
return Response(r.json())
But I'm getting this error:
HTTPConnectionPool(host='bfc.localhost', port=8000): Max retries exceeded with url: /o/token/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001E24200D600>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
I have tried to check the connection using:
socket.create_connection(('localhost',8000),timeout=2)
and
socket.create_connection(('bfc.localhost',8000),timeout=2)
bfc.localhost cant create a connection yet localhost and also I can access the domain from my browser
Additional info:
In Postman OAuth 2 section I can get a response with the same fields
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论