python - 操作系统错误 : [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

标签 python flask flask-mail python-huey

我正在尝试使用 Huey 作为跨平台任务队列。我找到了 https://github.com/pjcunningham/flask-huey-example ,我已经克隆并设置了一个用于使用 conda 的 virtualenv(我在 Windows 上工作)。我遵循了更新的自述文件,并设法让所有三个窗口都正常运行。但是,当我打开 http://localhost:6060/

[![在此处输入图像描述][2]][2]

我点击发送按钮,这打破了 Huey_consumer 过程:

$ python ...envs/hueytest1/Scripts/huey_consumer.exe run_huey.huey
[2018-08-06 10:19:25,949] INFO:huey.consumer:MainThread:Huey consumer started with 1 thread, PID 1704
[2018-08-06 10:19:25,949] INFO:huey.consumer:MainThread:Scheduler runs every 1 seconds.
[2018-08-06 10:19:25,949] INFO:huey.consumer:MainThread:Periodic tasks are enabled.
[2018-08-06 10:19:25,950] INFO:huey.consumer:MainThread:UTC is enabled.
[2018-08-06 10:19:25,950] INFO:huey.consumer:MainThread:The following commands are available:
+ send_async_email
+ dummy_task
[2018-08-06 10:19:39,743] INFO:huey.consumer.Worker:Worker-1:Executing queuecmd_send_async_email: ba5e092d-b1de-41cd-8b27-72d11c2b13d8
[2018-08-06 10:19:40,766] ERROR:huey.consumer.Worker:Worker-1:Unhandled exception in worker thread
Traceback (most recent call last):
  File "...\envs\hueytest1\lib\site-packages\huey\consumer.py", line 153, in process_task
    self.huey.execute(task)
  File "...\envs\hueytest1\lib\site-packages\huey\api.py", line 271, in execute
    result = task.execute()
  File "...\envs\hueytest1\lib\site-packages\huey\api.py", line 565, in execute
    return func(*args, **kwargs)
  File "E:\ENVS\r3\hueytest1\app\tasks.py", line 23, in send_async_email
    mail.send(msg)
  File "...\envs\hueytest1\lib\site-packages\flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "...\envs\hueytest1\lib\site-packages\flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "...\envs\hueytest1\lib\site-packages\flask_mail.py", line 158, in configure_host
    host = smtplib.SMTP(self.mail.server, self.mail.port)
  File "...\envs\hueytest1\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "...\envs\hueytest1\lib\smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "...\envs\hueytest1\lib\smtplib.py", line 307, in _get_socket
    self.source_address)
  File "...\envs\hueytest1\lib\socket.py", line 724, in create_connection
    raise err
  File "...\envs\hueytest1\lib\socket.py", line 713, in create_connection
    sock.connect(sa)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

我怎样才能让它工作?

最佳答案

尝试启动 Visdom 服务器时出现完全相同的错误:

OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

原因是有另一个进程使用与 Visdom 想要使用的端口相同的端口,在我的情况下是端口 8097。

为了调试这个,我遵循了以下步骤:
  • 使用 TcpView from Sysinternals使用端口查找进程。
  • 如果该进程是 svchost.exe,则您需要找到使用此端口的服务。为此,请运行以下命令:`tasklist/svc/FI "PID eq 1234"where replce 1234 from PID you see in TcpView.
  • 打开 Windows 服务小程序并查找此服务器。在我的情况下,结果是“交付优化”或 DOSvc 服务,如果您在大型网络上,它基本上使用 Windows 更新位的 P2P 下载。我暂时关闭了该服务并能够再次打开该端口。
  • 关于python - 操作系统错误 : [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709854/

    相关文章:

    python - 我正在尝试检测屏幕上的移动但收到错误 : ValueError: too many values to unpack (expected 4)

    python - SQLAlchemy 和原始 SQL : List as an input

    python - 在 Flask 上注册用户时发送邮件时出现循环导入问题

    python - 属性错误 : 'NoneType' object has no attribute 'app' when trying to send mail in Flask

    python - 短暂闪现一张图片

    python - 如何使用fcntl读取锁定文件的状态?

    python - 将表单数组发送到 Flask

    security - 将flask_mail 与gmail 结合使用有多安全?

    python - 防止链式回调将下拉菜单切换为原始值破折号

    python - 类型错误 : The return type must be a string, 字典、元组、响应实例或 WSGI 可调用,但它是一个列表