[英]Cannot run Python3 HTTPServer on ARM processor
I recently bought Odroid XU4 , a single-board computer with an ARM CPU. 我最近购买了具有ARM CPU的单板计算机Odroid XU4 。 I try to run a simple web server using HTTTPServer on Python3. 我尝试在Python3上使用HTTTPServer运行简单的Web服务器。
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
This code runs well on my Mac machine. 该代码在我的Mac机器上运行良好。 But when I try to run this on Odroid XU4, I got this error message. 但是,当我尝试在Odroid XU4上运行它时,出现了此错误消息。
$ python3 webserver.py
Traceback (most recent call last):
File "test.py", line 8, in <module>
with socketserver.TCPServer(("", PORT), Handler) as httpd:
AttributeError: __exit__
Can anyone explain why I got this error? 谁能解释我为什么会收到此错误? For your information, I've attached the information about the OS and Python interpreter. 为了给您提供信息,我附上了有关OS和Python解释器的信息。
$ uname -a
Linux odroid 4.9.44-54 #1 SMP PREEMPT Sun Aug 20 20:24:08 UTC 2017 armv7l armv7l armv7l GNU/Linu
$ python
Python 3.5.2 (default, Aug 18 2017, 17:48:00)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
From the documentation it would seem that the contextmanager protocol ( with ...
) form for TCPServer
's base class (and therefore TCPServer
was added in python3.6. This is not available in python3.5 从文档看来, TCPServer
的基类的contextmanager协议( with ...
)形式(因此TCPServer
已添加在python3.6中。在python3.5中不可用)
Changed in version 3.6: Support for the context manager protocol was added. 在版本3.6中更改:添加了对上下文管理器协议的支持。 Exiting the context manager is equivalent to calling
server_close()
. 退出上下文管理器等效于调用server_close()
。
Fortunately, you can use the previous approach. 幸运的是,您可以使用前面的方法。 This roughly means taking your with statement and turning it into a plain assignment: 这大致意味着要使用with语句并将其转换为简单的任务:
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.