Encoding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lad

    #1

    Encoding

    I have a script that uses utf-8 encoding. Now I would like to send some
    data to an application ( on another server) that uses 1250 encoding.
    How can I tell the server that the coming data will be in utf-8 code?
    I tried this
    params='some data'
    h = httplib.HTTP(se lf.host)
    h.putheader("Co ntent-type", "multipart/form-data;
    boundary=---------------------------7d329422844")
    h.putheader("Co ntent-length", "%d" % len(params))
    h.putheader("Ac cept-Language", "us-en")
    h.putheader('Ac cept', 'image/gif, image/x-xbitmap, image/jpeg,
    image/pjpeg, */*')
    h.putheader('Us er-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows
    NT 5.1)')
    h.putheader('Ho st', 'server')
    h.endheaders()
    ......
    .....

    but it doesn't work. The data are not encoded properly
    Thanks for help
    L.B.

  • Szabolcs Nagy

    #2
    Re: Encoding

    what about params='some data'.decode('u tf8').encode('1 250') ?

    Comment

    • Martin v. Löwis

      #3
      Re: Encoding

      Lad wrote:[color=blue]
      > I have a script that uses utf-8 encoding. Now I would like to send some
      > data to an application ( on another server) that uses 1250 encoding.
      > How can I tell the server that the coming data will be in utf-8 code?[/color]

      You can't, normally. In theory, you should put

      Content-type: text/plain;charset=u tf-8

      into the individual *part*. However, many implementations will ignore
      the charset= argument on a part.

      Instead, the convention is that the data must be transmitted in the
      encoding of the *HTML page* which contained the form you are submitting.

      So most likely, you need to recode your data.

      Regards,
      Martin

      Comment

      • Lad

        #4
        Re: Encoding

        Yes, 'some data'.decode('u tf8').encode('w indows-1250')
        works great.
        Thanks
        L.B.

        Comment

        Working...