推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wsds
V2EX  ›  Python

Python 多线程在内网通过接口下载图片时,报错 urlopen error[WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。

  •  
  •   wsds · Aug 8, 2018 · 3047 views
    This topic created in 2861 days ago, the information mentioned may be changed or developed.
    urlopen error[WinError 10048] 通常每个套接字地址(协议 /网络地址 /端口)只允许使用一次。
    

    这是怎么回事,各线程抢了端口了吗? 这样搞了一下,也没用

    s = requests.Session()
    s.keep_alive = False
    

    每个请求,用完后也 r.close() 了, 也没用,不知道啥原因,没见过这个错误啊, 有 v 友知道的吗

    11 replies    2020-09-28 09:46:06 +08:00
    hustlibraco
        1
    hustlibraco  
       Aug 8, 2018
    直接在 cmd 里运行 python 脚本,不要在 IDE 里运行
    GoLand
        2
    GoLand  
       Aug 8, 2018 via Android
    看图片是不是同一个域名下的,是同一个域名下为啥要关掉 keep-alive ?直接长连接不就好,如果不是一个域名下的就直接短连接吧。
    wsds
        3
    wsds  
    OP
       Aug 8, 2018
    @hustlibraco 就是在 cmd 中运行的
    wsds
        4
    wsds  
    OP
       Aug 8, 2018
    @GoLand requests 默认是开着的,就是出现了这个 10048,所以才关了,但也没用
    blodside
        5
    blodside  
       Aug 8, 2018
    把 python 进程先都关了
    wsds
        6
    wsds  
    OP
       Aug 8, 2018
    @blodside 只有这一个 python 进程,没有其他的啊,应该是多线程的问题
    hustlibraco
        7
    hustlibraco  
       Aug 8, 2018
    netstat -ano 看一下,是不是有些进程没有正常关闭,端口被占光了
    beastk
        8
    beastk  
       Aug 10, 2018 via iPhone
    线程数设置为多少,加了 sleep 了吗?
    wsds
        9
    wsds  
    OP
       Aug 10, 2018
    @beastk 线程数是根据参数列表自动设置的,目前是 9 个,没加 sleep
    victor11
        10
    victor11  
       Sep 28, 2020
    同问 我也遇到这问题 了
    victor11
        11
    victor11  
       Sep 28, 2020
    多进程 没问题 多线程就会出现 这种错误
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2986 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 14:35 · PVG 22:35 · LAX 07:35 · JFK 10:35
    ♥ Do have faith in what you're doing.