首页 > 解决方案 > Encoutering OSError: [WinError 10038] 使用 python 设置基本 http 代理时,尝试对非套接字的操作进行操作

问题描述

我试图使用 python 设置一个简单的 http-proxy,但我不断收到 OSError: [WinError 10038] An operation was trying on something that is not a socket ondata = 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');

标签: pythonsocketshttpserverproxy

解决方案


推荐阅读