无法在ARM处理器上运行Python3 HTTPServer [英] Cannot run Python3 HTTPServer on ARM processor

查看:126
本文介绍了无法在ARM处理器上运行Python3 HTTPServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了 Odroid HTTTPServer 运行一个简单的Web服务器./p>

I recently bought Odroid XU4, a single-board computer with an ARM CPU. I try to run a simple web server using HTTTPServer on Python3.

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()

此代码在我的Mac机器上运行良好.但是,当我尝试在Odroid XU4上运行它时,出现了此错误消息.

This code runs well on my Mac machine. But when I try to run this on Odroid XU4, I got this error message.

$ python3 webserver.py
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    with socketserver.TCPServer(("", PORT), Handler) as httpd:
AttributeError: __exit__

任何人都可以解释为什么我会收到此错误吗?为了给您提供信息,我们在此附上了有关操作系统和Python解释器的信息.

Can anyone explain why I got this error? For your information, I’ve attached the information about the OS and Python interpreter.

$ 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.
>>>

推荐答案

来自文档看来, TCPServer 的基类的上下文管理器协议( with ... )形式(因此, TCPServer 在python3.6中添加.在python3.5中不可用

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

在3.6版中进行了更改:添加了对上下文管理器协议的支持.退出上下文管理器等效于调用 server_close().

幸运的是,您可以使用前面的方法.这大致意味着要使用with语句并将其转换为简单的作业:

Fortunately, you can use the previous approach. This roughly means taking your with statement and turning it into a plain assignment:

httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()

这篇关于无法在ARM处理器上运行Python3 HTTPServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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