Python中文
首页
教程
问答
标签
搜索
登录
注册
BaseHTTPServer.BaseHTTPRequestHandler utf-8问题
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我对HTML中显示的文本有问题“BaseHTTPServer.BaseHTTPRequestHandler“回答。HTML页面接收一个包含utf-8字符的字符串值并将其显示在文本框中,但是utf-8字符是可见的。 该值以以下格式保存在xml文件中:<code>[15-09-02 10:16:45] Testing%2Bthe%2Bcomments%2Bpage</code>,由python脚本读取,并使用以下url在页面中调用:</p> <pre><code>htt://URL/Comments?group=BLABLA&unit=YUO&info=[15-09-02 10:16:45] Testing%2Bthe%2Bcomments%2Bpage&another= </code></pre> <p>但是,html页面在文本框中显示以下文本:</p> ^{pr2}$ <p>在没有删除特殊字符的情况下,我尝试了字符串中的encode().decode(),但没有任何效果。有人知道吗? 用于创建Web服务器的代码:</p> <pre><code>class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_HEAD(s): s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() def do_GET(s): """Respond to a GET request.""" s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() if("/Comments" in s.path): strServer = "http://" + HOST_NAME + ":" + str(PORT_NUMBER) + "/SaveComments"; strUrl = s.path; s.wfile.write(CommentsPage.IndexPage(strUrl, strServer)); elif("/SaveComments" in s.path): s.wfile.write(CommentsPage.SaveComments(s.path)); else: s.wfile.write(CommentsPage.ErrorPage()); if __name__ == '__main__': server_class = BaseHTTPServer.HTTPServer httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler) print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) try: httpd.serve_forever() except <a href="https://www.cnpython.com/pypi/keyboard" class="inner-link">keyboard</a>Interrupt: pass httpd.server_close() print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER) </code></pre> <p>返回html页的函数:</p> <pre><code>def IndexPage(strUrl, strServer): ... strPage = "<!DOCTYPE html><html>"; strPage = strPage + "<head><title>Match report comments.</title></head>"; strPage = strPage + "<body><form action=\"" + strServer + "\">"; strPage = strPage + "Group:<br><input type=\"text\" name=\"group\" value=\"" + arrGroupValue[1] + "\">"; strPage = strPage + "<br>Unit:<br><input type=\"text\" name=\"unit\" value=\"" + strUnit + "\">"; strPage = strPage + "<br>Information:<br><textarea rows=\"8\" cols=\"30\" name=\"info\">" + strInfo + "</textarea>"; strPage = strPage + "<br>Resp:<br><input type=\"text\" name=\"responsible\" value=\"" + strResp + "\">"; strPage = strPage + "<br><br><input type=\"submit\" value=\"Submit\"></form></body></html>"; return strPage; </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>实际上,解决方案是使用<code>urllib.unquote</code>。当url保存在xml文件中时,在必须使用<code>urllib.quote(url)</code>格式化之前,以及在第一次从文件中读取它时,必须使用<code>urllib.unquote(read_url)</code>进行格式化。然而,空格被“+”符号代替,函数字符串。替换()解决了这个问题。谢谢你的帮助!在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
1 回答
如何添加表示整数的擦边字符串?
5 回答
如何添加要在Bokeh中使用的新font.ttf文件?
5 回答
如何添加要显示的矩阵XY轴编号和XY轴
6 回答
如何添加计数?
7 回答
如何添加计数器函数?
8 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
4 回答
如何添加计数器来跟踪while循环中的月份和年份?
10 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
8 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
3 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
9 回答
如何添加评论拉梅尔亚姆
4 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
2 回答
如何添加谷歌地点自动完成到Flask?
5 回答
如何添加超时、python discord bot
6 回答
如何添加超过1dp的检查
5 回答
如何添加距离方法
6 回答
如何添加跟随游戏的敌人精灵
5 回答
如何添加路径以便python可以找到程序?
10 回答
如何添加身份验证/安全性以使用happybase访问HBase?
5 回答