html网页中制作遇到的问题,python 制作网页 遇到的问题

在尝试使用Python的Remi库创建网页时,遇到了UnicodeDecodeError,错误指出'utf-8'编码无法解码字节0xbf。问题出现在启动web服务器时,可能与文件或环境的编码设置有关。尝试更换Python版本从3.8到3.5后,问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用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

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 的

3b8b03947f1491f32f732f9738cec8eb.png

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

回答

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值