Lispython / human_curl

Simple Human wrapper for cURL library
http://h.wrttn.me/human_curl
Other
205 stars 43 forks source link

unicode support #11

Open imbolc opened 12 years ago

imbolc commented 12 years ago
>>> import requests
>>> requests.get(u'http://google.com/')
<Response [200]>
>>> import human_curl as requests
>>> requests.get(u'http://google.com/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/human_curl/methods.py", line 93, in get
    return request("GET", url, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/human_curl/methods.py", line 76, in request
    r.send()
  File "/usr/local/lib/python2.6/dist-packages/human_curl/core.py", line 312, in send
    opener, body_output, headers_output = self.build_opener(self._build_url())
  File "/usr/local/lib/python2.6/dist-packages/human_curl/core.py", line 348, in build_opener
    opener.setopt(pycurl.URL, url)
TypeError: invalid arguments to setopt

То же самое при передаче юникода в params и т.п.

Lispython commented 12 years ago

Надо подумать над решением. Проблема в том, что pycurl (сишная часть) не понимает тип unicode питона. Поэтому надо декодить в обычный стринг, что не всегда возможно.

imbolc commented 12 years ago

Можно у requests посмотреть. Оно ж и urllib не работает с юникодом:

>>> urllib.quote(u'тест')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/urllib.py", line 1224, in quote
    res = map(safe_map.__getitem__, s)
KeyError: u'\u0442'

У них даже response.text есть, который юникод возвращает. Они chardet используют и аттрибут encoding есть.

honzajavorek commented 10 years ago

I don't understand a word from your conversation, but the library is almost for no use without the unicode support. It raises exceptions over and over just because my url, data, proxy, or whatever else parameters are in unicode strings - does not matter they actually contain only ASCII. This is a deal-breaker.