Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:11:25+00:00 2026-06-01T20:11:25+00:00

I try to post unicode data with the httplib.request function: s = uעברית data

  • 0

I try to post unicode data with the httplib.request function:

s = u"עברית"
data = """
<spellrequest textalreadyclipped="0" ignoredups="1" ignoredigits="1" ignoreallcaps="0">
<text>%s</text>
</spellrequest>
""" % s

con = httplib.HTTPSConnection("www.google.com")
con.request("POST", "/tbproxy/spell?lang=he", data)
response = con.getresponse().read()

However this is my error:

Traceback (most recent call last):
  File "C:\Scripts\iQuality\test.py", line 47, in <module>
    print spellFix(u"╫á╫נ╫¿╫ץ╫ר╫ץ")
  File "C:\Scripts\iQuality\test.py", line 26, in spellFix
    con.request("POST", "/tbproxy/spell?lang=%s" % lang, data)
  File "C:\Python27\lib\httplib.py", line 955, in request
    self._send_request(method, url, body, headers)
  File "C:\Python27\lib\httplib.py", line 989, in _send_request
    self.endheaders(body)
  File "C:\Python27\lib\httplib.py", line 951, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 815, in _send_output
    self.send(message_body)
  File "C:\Python27\lib\httplib.py", line 787, in send
    self.sock.sendall(data)
  File "C:\Python27\lib\ssl.py", line 220, in sendall
    v = self.send(data[count:])
  File "C:\Python27\lib\ssl.py", line 189, in send
    v = self._sslobj.write(data)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 97-102: or
dinal not in range(128)

Where am I wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:11:26+00:00Added an answer on June 1, 2026 at 8:11 pm

    http is not defined in terms of a particular character encoding, and instead uses octets. You need to convert your data to an encoding, and then you need to tell the server which encoding you have used. Lets use utf8, since it’s usually the best choice:

    This data looks a bit like XML, but you are skipping the xml tag. Some services may accept that, but you shouldn’t anyways. In fact, the encoding actually belongs there; so make sure you include it. The heading looks like <?xml version="1.0" encoding="encoding"?>.

    s = u"עברית"
    data_unicode = u"""<?xml version="1.0" encoding="UTF-8"?>
    <spellrequest textalreadyclipped="0" ignoredups="1" ignoredigits="1" ignoreallcaps="0">
    <text>%s</text>
    </spellrequest>
    """ % s
    
    data_octets = data_unicode.encode('utf-8')
    

    As a matter of courtesy, you should also tell the server itself the format and encoding, with the content-type header:

    con = httplib.HTTPSConnection("www.google.com")
    con.request("POST",
                "/tbproxy/spell?lang=he", 
                data_octets, {'content-type': 'text/xml; charset=utf-8'})
    

    EDIT: It’s working fine on my machine, are you sure you’re not skipping something? full example

    >>> from cgi import escape
    >>> from urllib import urlencode
    >>> import httplib
    >>> 
    >>> template = u"""<?xml version="1.0" encoding="UTF-8"?>
    ... <spellrequest textalreadyclipped="0" ignoredups="1" ignoredigits="1" ignoreallcaps="0">
    ... <text>%s</text>
    ... </spellrequest>
    ... """
    >>> 
    >>> def chkspell(word, lang='en'):
    ...     data_octets = (template % escape(word)).encode('utf-8')
    ...     con = httplib.HTTPSConnection("www.google.com")
    ...     con.request("POST",
    ...         "/tbproxy/spell?" + urlencode({'lang': lang}),
    ...         data_octets,
    ...         {'content-type': 'text/xml; charset=utf-8'})
    ...     req = con.getresponse()
    ...     return req.read()
    ... 
    >>> chkspell('baseball')
    '<?xml version="1.0" encoding="UTF-8"?><spellresult error="0" clipped="0" charschecked="8"></spellresult>'
    >>> chkspell(corpus, 'he')
    '<?xml version="1.0" encoding="UTF-8"?><spellresult error="0" clipped="0" charschecked="5"></spellresult>'
    

    I did notice that when I pasted your example, it appears in the opposite order on my terminal from how it shows in my browser. Not too surprising considering Hebrew is a right-to-left language.

    >>> corpus = u"עברית"
    >>> print corpus[0]
    ע
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to post data by ajax , it gives me name value bu
I try to perform a simple POST-request with urllib2. However the servers response indicates
I try PHP Post Request inside a POST Request thinking it might be useful
When I try to post data from http to https, urllib2 does not return
I try to post some data via json objects to my asp.net mvc view,
HttpRequestValidationException occurs when I try post when txtBulletin contains any HTML, like Hello<br />World
Every time I try to post to twitter in my rails app, the first
I could try to post and explain the exact query I'm trying to run,
JQuery mobile and Adsense mobile ads don't mix together. When I try to post
When I try to convert an HTTP POST response to JSONArray I get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.