Hello all,
I hope this is the correct newsgroup for this question.
Does anybody know how I can write a html-header with python(cgi)?
The problem is, I have a few html templates in which I have a header e.g:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
In this template I write a few Mysql variables.
Those variable often have german characters. This characters (Gösing in
stead of Gösing). The german characters in the html template are shown
correctly.
If I change the character encoding with the browser to utf-8, all the characters are shown correctly.
As you can see, I put in the header of the html template that the encoding
is UTF-8, the browser still shows windows ISO-8859-15. Can I write the
header with python so the browser uses the utf-8 encoding?
My hosting providor uses fedora core 2, Python 2.2.3, MySQLdb. Mysql 3.23.58
I googled for hours, but I can't find the answer. I hope ypu can help me.
Thanks in advance.
Arjen 3 2620
db wrote: In this template I write a few Mysql variables. Those variable often have german characters. This characters (Gösing in stead of Gösing). The german characters in the html template are shown correctly.
The problem is then with these variables: apparently, the Mysql
variables are encoded in iso-8859-15, and you need to recode them
to UTF-8 first before putting them into the template.
var = var.decode("iso-8859-15").encode("ut f-8")
As you can see, I put in the header of the html template that the encoding is UTF-8, the browser still shows windows ISO-8859-15. Can I write the header with python so the browser uses the utf-8 encoding?
The problem is not the header, but the body. The browser sees your claim
that the page is UTF-8, but doesn't believe it. This is because it tries
to interpret the page as UTF-8, and then finds invalid byte sequences
(your latin-9 characters), and then knows that the page *can't* be
UTF-8. It then guesses that the page must be latin-something. That guess
is wrong, of course, also, because some characters in the page are
utf-8, and others latin-9. This is invalid HTML.
Regards,
Martin
db wrote: Hello all,
I hope this is the correct newsgroup for this question.
Does anybody know how I can write a html-header with python(cgi)? The problem is, I have a few html templates in which I have a header e.g:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
In this template I write a few Mysql variables. Those variable often have german characters. This characters (Gösing in stead of Gösing). The german characters in the html template are shown correctly.
If I change the character encoding with the browser to utf-8, all the characters are shown correctly. As you can see, I put in the header of the html template that the encoding is UTF-8, the browser still shows windows ISO-8859-15. Can I write the header with python so the browser uses the utf-8 encoding?
My hosting providor uses fedora core 2, Python 2.2.3, MySQLdb. Mysql 3.23.58
I googled for hours, but I can't find the answer. I hope ypu can help me.
Does your browser send a Content-Type HTTP header (don't confuse this with
the HTML <head> part)? If it does and it specifies a charset, this will
override your <meta http-equiv>. Often iso-8859-1 is the default charset
for the Content-Type header.
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
db wrote: Hello all,
I hope this is the correct newsgroup for this question.
Does anybody know how I can write a html-header with python(cgi)? The problem is, I have a few html templates in which I have a header e.g:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
If you are using CGI you can set the Content-Type header directly. Before you output your HTML do
print "Content-Type: text/html; charset=UTF-8"
print # blank line, end of headers
Kent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard Lewis |
last post by:
Hi there,
I'm having a problem with unicode files and ftplib (using Python 2.3.5).
I've got this code:
xml_source = codecs.open("foo.xml", 'w+b', "utf8")
#xml_source = file("foo.xml", 'w+b')
ftp.retrbinary("RETR foo.xml", xml_source.write)
|
by: hunterb |
last post by:
I have a file which has no BOM and contains mostly single byte chars. There
are numerous double byte chars (Japanese) which appear throughout. I need to
take the resulting Unicode and store it in a DB and display it onscreen. No
matter which way I open the file, convert it to Unicode/leave it as is or
what ever, I see all single bytes ok, but double bytes become 2 seperate
single bytes. Surely there is an easy way to convert these mixed...
|
by: EmeraldShield |
last post by:
We have an application that uses UTF8 everywhere to load / save / process
documents.
One of our clients is having a problem with BIG Encoded files being trashed
after running through our app.
Indeed I have verified that if I go to a website in Taiwan and save the file
in BIG5 and then just load / save the file with a UTF8 text reader / write
some bytes are modified.
How can I correct this? It was my understanding the UTF8 was...
|
by: Matt |
last post by:
I have a problem where I am working with extended character sets in XML but
I have also found that any time I work with a translation or internally
generated Xml document I get the dreaded message, "Data at the root level is
invalid. Line 1 position 1".
If you run the following code there will be extra bytes at the beginning of
the resulting string. I believe this is some type of BigEndian encoding or
something. My question is this,...
|
by: EmeraldShield |
last post by:
(Dot Net 2 C# application - using Encoding.UTF8 with a StreamReader)
I have a very strange problem that I cannot explain with a UTF8 Readline()
although this could exist in other types of encoding, I have not tried them.
Our application wrote this sequence to a UTF8 file. Now I am loading it
back and the text is not coming back in the same as it went out.
DATA:
from: processfrom checkemail failed: 501 syntax error in parameters:...
| |
by: amygdala |
last post by:
Hi,
I'm trying to let PHP write a 'sitemap.xml' sitemap for Google and other
searchengines. It's working, except that the content in the XML file doesn't
seem to be UTF8. (Which it should be, judging by the information given on
Google's webmaster helpcenter).
The way I test to see if the content is UTF8, is by opening the XML file in
notepad and choose 'save as...'. Normally the coding option should be set to
UTF8, but now it just...
|
by: |
last post by:
Hi all,
I want to create a method that does the following:
1) Programmatically instantiate a new XmlDataSource control
2) For each file in a named directory, make a "FileSystemItem" element
3) On each FileSystemItem Element, make two child nodes, one with the file
name, one with the file size. ie.
<filesystemitems>
<filesystemitem>
|
by: darrel |
last post by:
I was having issues before with my XML being sent to the browser as UTF16.
Via my XmlTextWriter, was able to fix this by explicitely setting the
encoding to UTF8:
Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
That fixed the issue.
I'm not generating an XML file using a different method grabbing XML from a
DB and then reading it in as a stringreader, then transforming that via an
|
by: Samuel |
last post by:
Hi
I am trying to write to a string text encoded to utf8 as oppose to utf16
Since the data comes from an XML object (and I serialize it) I need to pass
either StreamWriter or a StringWriter object, I don't want to create a file
so I want to use a StringWriter (passing to it's constructor a
StringBuilder) The problem is that the StringWriter encodes utf16 (I don't
know how to change it)
|
by: islandgal |
last post by:
--
-- Table structure for table borrower
--
DROP TABLE IF EXISTS borrower;
CREATE TABLE borrower (
brw_num int(11) NOT NULL default '0',
brw_lname varchar(15) default NULL,
brw_fname varchar(15) default NULL,
brw_initial varchar(1) default NULL,
brw_areacode varchar(3) default NULL,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |