对python httplib中的一个无法访问的网络进行了套接字操作 [英] A socket operation was attempted to an unreachable network in python httplib

查看:284
本文介绍了对python httplib中的一个无法访问的网络进行了套接字操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用httplib从django创建一个REST客户端。但是拒绝连接
我尝试了以下

I am trying to make a REST client from django using httplib . But it is refusing the connection I tried the following

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),因为它没有从一个到另一个配置网络路由。

The error indicates that your the machine you are running this script on cannot reach the destination IP address (10.0.2.2), as it doesn't have a network route configured from one to the other.

这是您的内部网络的一个问题(10。 xxx IP地址始终是专用网络地址)。如果您在与您尝试访问的计算机不同的网络上运行此脚本,则需要一个公共IP地址。

This is a problem with your internal network (10.x.x.x IP addresses are always private network addresses). If you are running this script on a different network from the machine you are trying to reach, you'll need a public IP address for it instead.

这篇关于对python httplib中的一个无法访问的网络进行了套接字操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆