Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
遇到OSError:[WinError 10038]在使用python设置基本http代理时,尝试对非套接字的对象执行操作_Python_Sockets_Http_Server_Proxy - Fatal编程技术网

遇到OSError:[WinError 10038]在使用python设置基本http代理时,尝试对非套接字的对象执行操作

遇到OSError:[WinError 10038]在使用python设置基本http代理时,尝试对非套接字的对象执行操作,python,sockets,http,server,proxy,Python,Sockets,Http,Server,Proxy,我试图使用python设置一个简单的http代理,但我一直收到OSError:[WinError 10038]试图在data=conn.recv(1024) 我做错了什么?我的主要职能 def main(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((

我试图使用python设置一个简单的http代理,但我一直收到OSError:[WinError 10038]试图在
data=conn.recv(1024)

我做错了什么?我的主要职能

def main():
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind((HOST, PORT))
        s.listen()

        while True:
            conn, addr = s.accept()
            # get the next valid HTTP request
            buffer = b''
            while True:

                with conn:
                    print('Connected by: ', addr)
                data = conn.recv(1024)
                if not data:
                    break
                buffer = buffer + data;

                req, buffer = parse_message(buffer)
                if req is not None:
                    print('success');

带有conn:的
块很可能在插座退出时关闭插座
conn
。删除这个被封锁的答案@IainShelvington我一直认为这是
with
语句,但请原谅
conn
我在PyCharm中从cmd运行flask时遇到了这个错误。切换到Windows CMD窗口,错误消失。