使用python unicode cgi-bin脚本需要帮助 [英] Help needed with python unicode cgi-bin script

查看:76
本文介绍了使用python unicode cgi-bin脚本需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的网神:


经过多次努力,与unicode相比,在一个小时内阅读了所有

的例子,编码,测试他们,将他们拆开并将他们重新组合在一起,我很谦卑。因此,我在你之前谦虚地讨论一个简单的python unicode cgi-bin脚本问题。


我的问题比这更复杂,但是怎么样我可以把一个坚持下来的原因归结为
点。我有一个带有西班牙语单词的文件,a?os,我希望通过以下方式阅读:
#!C:/ Program Files / Python23 /python.exe


STARTHTML = u''''''内容类型:text / html


<!DOCTYPE html PUBLIC " - // W3C // DTD XHTML 1.0 Transitional // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns =" http://www.w3.org/1999/xhtml"郎= QUOT;恩" xml:lang =" en">

< head>

< / head>

< body>

'''''

ENDHTML =你''''

< / body>

< ; / html>

''''''

打印STARTHTML

打印打开(''c:/test/spanish.txt' ',''r'')。read()

print ENDHTML

而不是看到a?o我看到a?o。 BAD BAD BAD BAD

然而,如果我用浏览器(IE / Mozilla)打开文件,我会看到a?o。。这是

我想要什么


提供什么?


接下来,我会进入编解码器和什么,但是从这开始怎么样?


一般的问题是,是否有人有一个完整的工作示例

cgi-bin脚本执行他们愿意分享这些内容吗?

我在网上尝试了各种各样的例子,但却无法上班。

我最终看到非ascii字符u''a \ xf1o''的十六进制代码,以及后来

''a \\\ xc3 \ xb1o'',这些也是坏不好的。


谢谢 - 你卑微的请求者。

Dear web gods:

After much, much, much struggle with unicode, many an hour reading all the
examples online, coding them, testing them, ripping them apart and putting
them back together, I am humbled. Therefore, I humble myself before you to
seek guidance on a simple python unicode cgi-bin scripting problem.

My problem is more complex than this, but how about I boil down one sticking
point for starters. I have a file with a Spanish word in it, "a?os", which I
wish to read with:
#!C:/Program Files/Python23/python.exe

STARTHTML= u''''''Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
</head>
<body>
''''''
ENDHTML = u''''''
</body>
</html>
''''''
print STARTHTML
print open(''c:/test/spanish.txt'',''r'').read()
print ENDHTML
Instead of seeing "a?o" I see "a?o". BAD BAD BAD
Yet, if I open the file with the browser (IE/Mozilla), I see "a?o." THIS IS
WHAT I WANT

WHAT GIVES?

Next, I''ll get into codecs and stuff, but how about starting with this?

The general question is, does anybody have a complete working example of a
cgi-bin script that does the above properly that they''d be willing to share?
I''ve tried various examples online but haven''t been able to get any to work.
I end up seeing hex code for the non-ascii characters u''a\xf1o'', and later
on ''a\xc3\xb1o'', which are also BAD BAD BAD.

Thanks -- your humble supplicant.

推荐答案

你可能需要将stdout模式设置为二进制。它们默认不是Windows $

weheh < we *** @ verizon.netwrote in message

news:DV57j.11710
You probably need to set stdout mode to binary. They are not by default on
Windows.
"weheh" <we***@verizon.netwrote in message
news:DV57j.11710


OR.11141@trnddc01 ...
OR.11141@trnddc01...

亲爱的网神:


经过很多很多很多努力与unicode,很多一个小时阅读所有

在线示例,编码,测试它们,将它们分开并将它们重新组合在一起,我很谦卑。因此,我在你之前谦虚地讨论一个简单的python unicode cgi-bin脚本问题。


我的问题比这更复杂,但是我怎么样才能为初学者留下一个好的b $ b b点。我有一个带有西班牙语单词的文件,a?os,

我希望阅读:


#!C:/程序文件/ Python23 / python.exe


STARTHTML = u''''''内容类型:text / html

< !DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 dtd">

< html xmlns =" http://www.w3.org/1999/xhtml"郎= QUOT;恩" xml:lang =" en">

< head>

< / head>

< body>

'''''

ENDHTML =你''''

< / body>

< ; / html>

''''''

打印STARTHTML

打印打开(''c:/test/spanish.txt' ',''r'')。read()

print ENDHTML


而不是看到a?o我看到a?o。 BAD BAD BAD BAD

然而,如果我用浏览器(IE / Mozilla)打开文件,我会看到a?o。。这个

我想要什么


给什么?


接下来,我会进入编解码器和什么,但是从这开始怎么样?


一般的问题是,是否有人有一个完整的工作示例

cgi-bin脚本执行以上他们愿意支持
分享?我在网上尝试过各种各样的例子但是还没有能够得到任何工作的b $ b。我最终看到了非ascii字符的十六进制代码u''a \ xf1o'',

以及后来的''a \\\ xc3 \ xb1o'',这些也是不好的坏了。


谢谢 - 你谦卑的请求者。
Dear web gods:

After much, much, much struggle with unicode, many an hour reading all the
examples online, coding them, testing them, ripping them apart and putting
them back together, I am humbled. Therefore, I humble myself before you to
seek guidance on a simple python unicode cgi-bin scripting problem.

My problem is more complex than this, but how about I boil down one
sticking point for starters. I have a file with a Spanish word in it, "a?os",
which I wish to read with:
#!C:/Program Files/Python23/python.exe

STARTHTML= u''''''Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
</head>
<body>
''''''
ENDHTML = u''''''
</body>
</html>
''''''
print STARTHTML
print open(''c:/test/spanish.txt'',''r'').read()
print ENDHTML
Instead of seeing "a?o" I see "a?o". BAD BAD BAD
Yet, if I open the file with the browser (IE/Mozilla), I see "a?o." THIS
IS WHAT I WANT

WHAT GIVES?

Next, I''ll get into codecs and stuff, but how about starting with this?

The general question is, does anybody have a complete working example of a
cgi-bin script that does the above properly that they''d be willing to
share? I''ve tried various examples online but haven''t been able to get any
to work. I end up seeing hex code for the non-ascii characters u''a\xf1o'',
and later on ''a\xc3\xb1o'', which are also BAD BAD BAD.

Thanks -- your humble supplicant.



我的问题比这个,但是我怎么样才能把一个坚持
My problem is more complex than this, but how about I boil down one sticking

点作为首发。我有一个带有西班牙语单词的文件,a?os,我希望用以下内容读取
point for starters. I have a file with a Spanish word in it, "a?os", which I
wish to read with:



什么是该文件的编码?如果没有正确回答那个问题,你将无法达到你想要的效果。


可能的答案是iso-8859-1 ,utf-8,windows-1252和cp850

(这些都支持单词a?os)

What is the encoding of that file? Without a correct answer to that
question, you will not be able to achieve what you want.

Possible answers are "iso-8859-1", "utf-8", "windows-1252", and "cp850"
(these all support the word "a?os")


而不是看到a?o我看到a?o。 BAD BAD BAD
Instead of seeing "a?o" I see "a?o". BAD BAD BAD



我在这里什么都看不到。你在哪里看到问号?你是否可以在网络服务器上运行CGI脚本,并将你的网络浏览器指向网页,并在网页浏览器中看到问号?

I don''t see anything here. Where do you see the question mark? Did you
perhaps run the CGI script in a web server, and pointed your web browser
to the web page, and saw the question mark in the web browser?


提供什么?
WHAT GIVES?



发送"内容类型:text / html"是不足够的。 Web浏览器需要

才能知道编码是什么。所以你应该发送


内容类型:text / html; charset =" your-encoding-here"

使用extras / page information在Firefox中找出什么网页

浏览器认为该页面的编码是。


问候,

Martin


PS请停止喊叫。

Sending "Content-type: text/html" is not enough. The web browser needs
to know what the encoding is. So you should send

Content-type: text/html; charset="your-encoding-here"

Use "extras/page information" in Firefox to find out what the web
browser thinks the encoding of the page is.

Regards,
Martin

P.S. Please, stop shouting.


这篇关于使用python unicode cgi-bin脚本需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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