我正在尝试使用 httplib 从 django 创建 REST 客户端。但它拒绝连接
我尝试了以下方法
import hashlib
import hmac
from django.shortcuts import render_to_response
from django.template import RequestContext
def loginAction(request):
username=request.POST['email']
password=request.POST['password']
import httplib, urllib
params = urllib.urlencode({'username': username})
#hash username here to authenticate
digest=hmac.new("qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50", str(request.POST['password']),hashlib.sha1).hexdigest()
auth=username+":"+digest
headers = {"Content-type": "application/json","Accept": "text/plain","Authorization":auth}
conn = httplib.HTTPConnection("10.0.2.2",8000)
conn.request("POST", "/api/ecp/profile/", params, headers)
但给出以下错误
[Errno 10051] A socket operation was attempted to an unreachable network
可能是什么问题?
该错误表明您运行此脚本的计算机无法到达目标 IP 地址 (10.0.2.2),因为它没有配置从一台计算机到另一台计算机的网络路由。
这是您的内部网络的问题(10.x.x.x IP 地址始终是专用网络地址)。如果您在与尝试访问的计算机不同的网络上运行此脚本,则需要为其提供公共 IP 地址。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)