socket.error:[Errno 13]创建假电子邮件服务器时,权限被拒绝 [英] socket.error: [Errno 13] Permission denied when creating a fake email server

查看:935
本文介绍了socket.error:[Errno 13]创建假电子邮件服务器时,权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个虚假的电子邮件服务器作为Flask应用程序的一部分,通过使用以下脚本在控制台上输出错误。但是,它会抛出一个错误。

  dpadmins -MacBook:微博演示文稿$ python -m smtpd -n -c DebuggingServer localhost:25 

Traceback(最近的最后一次调用):
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py,第162行,在_run_module_as_main
__main__,fname,loader,pkg_name)
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py,第72行,在_run_code中
在run_globals中执行代码
在< module>文件中的/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtpd.py,第536行;
(options.remotehost,options.remoteport))
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtpd.py,第285行, __init__
self.bind(localaddr)
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py,行342,绑定
返回self.socket.bind(addr)
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py,第224行,在meth
return getattr(self._sock,name)(* args)
socket.error:[Errno 13] Permission denied

$ b $在Unix(Linux,Mac OS X,BSD等)系统中,普通用户不能绑定小于1024的端口,只有root用户才可以绑定到这些端口。



为了解决这个问题,你可以运行你的python应用程序作为根目录(通过使用sudo),但是这不是最好的。是否有可能让你的Flask应用程序在更高的端口上与本地主机对话,比如2525?然后你需要修改你用来启动SMTP端口2525而不是25端口的命令。


I'm trying to create a fake email server as part of a Flask app to print out errors on the console by using the following script. However, it throws an error. How can I fix this?

dpadmins-MacBook:microblog presentation$ python -m smtpd -n -c DebuggingServer localhost:25

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162,     in _run_module_as_main
"__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
  exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtpd.py", line 536,  in <module>
  (options.remotehost, options.remoteport))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtpd.py", line 285, in __init__
 self.bind(localaddr)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py", line 342, in bind
 return self.socket.bind(addr)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
 return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied

解决方案

In unix (Linux, Mac OS X, BSD etc) systems, ports less than 1024 can not be bound to by normal users, only the root user can bind to those ports.

To get around this, you could run your python application as root (by using sudo), however this is not preferable. Is it possible instead to get your Flask application to talk to localhost on a higher port, say 2525? You would then need to modify the command you are using to start the smtp server to bind on port 2525 rather than 25.

这篇关于socket.error:[Errno 13]创建假电子邮件服务器时,权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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