首页 新闻 会员 周边

python 制作网页 遇到的问题

0
悬赏园豆:10 [已解决问题] 解决于 2021-06-08 07:49

在使用python 制作网页时 遇到个这个问题
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 0: invalid start byte

先看代码

import remi.gui as gui
from remi import start, App


class MyApp(App):
    def __init__(self, *args):
        super(MyApp, self).__init__(*args)

    def main(self):
        wid = gui.VBox(width=300, height=200, margin='0px auto')
        self.lbl = gui.Label('Press the button', width='80%', height='50%')
        self.lbl.style['margin'] = 'auto'
        self.bt = gui.Button('Press me!', width=200, height=30)
        self.bt.style['margin'] = 'auto 50px'

        # setting the listener for the onclick event of the button
        self.bt.onclick.do(self.on_button_pressed)

        # appending a widget to another, the first argument is a string key
        wid.append(self.lbl)
        wid.append(self.bt)

        # returning the root widget
        return wid

    # listener function
    def on_button_pressed(self, widget):
        self.lbl.set_text('A notification message should appear.')
        self.bt.set_text('Hi!')
        self.notification_message("Message title", "Hello world!", "")


if __name__ == "__main__":
    # starts the webserver
    # optional parameters
    # start(MyApp,address='127.0.0.1', port=8081, multiple_instance=False,enable_file_cache=True, update_interval=0.1,
    # start_browser=True)
    start(MyApp, debug=True, address='0.0.0.0', port=0, )

这是报错

D:\Learn\Anaconda3\python.exe D:/Learn/PyCharm/(44)英语学习助手/Html/test2.py
Traceback (most recent call last):
File "D:/Learn/PyCharm/(44)英语学习助手/Html/test2.py", line 38, in <module>
start(MyApp, debug=True, address='0.0.0.0', port=0, )
File "D:\Learn\Anaconda3\lib\site-packages\remi\server.py", line 928, in start
s = Server(main_gui_class, start=True, **kwargs)
File "D:\Learn\Anaconda3\lib\site-packages\remi\server.py", line 819, in init
self.start()
File "D:\Learn\Anaconda3\lib\site-packages\remi\server.py", line 833, in start
self._sserver = ThreadedHTTPServer((self._address, self._sport), self._gui, self._auth,
File "D:\Learn\Anaconda3\lib\site-packages\remi\server.py", line 765, in init
HTTPServer.init(self, server_address, RequestHandlerClass)
File "D:\Learn\Anaconda3\lib\socketserver.py", line 452, in init
self.server_bind()
File "D:\Learn\Anaconda3\lib\http\server.py", line 140, in server_bind
self.server_name = socket.getfqdn(host)
File "D:\Learn\Anaconda3\lib\socket.py", line 756, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 0: invalid start byte

进程已结束,退出代码为 1

这似乎是说我的编码格式有问题 但是我的编码格式是utf-8 的

请大佬帮忙看看是什么情况

木三136的主页 木三136 | 初学一级 | 园豆:159
提问于:2021-05-31 11:33
< >
分享
最佳答案
0

换一个python的版本试试 我将3.8的换成了3.5的 就好了

木三136 | 初学一级 |园豆:159 | 2021-05-31 16:57
其他回答(1)
0

看这个错误提示的话,和代码本身没有关系,还是编码的问题。
应该是BOM头没有识别,你看看这个 https://www.cnblogs.com/yizhenfeng168/p/6938149.html

收获园豆:10
。淑女范erり | 园豆:961 (小虾三级) | 2021-05-31 16:53

首先感谢您的回答
试过这个了 发现还是不行
我换了个python版本 然后就好了0.0

支持(0) 反对(0) 木三136 | 园豆:159 (初学一级) | 2021-05-31 16:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册