Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Last active August 29, 2015 14:17
Show Gist options
  • Save taddeimania/d6f4a5dbd4755a75f53d to your computer and use it in GitHub Desktop.
Save taddeimania/d6f4a5dbd4755a75f53d to your computer and use it in GitHub Desktop.
Hy throwing error parsing response.
;; response_parse.py
;; import requests
;; response = requests.get("https://asciinema.org/api/asciicasts/17675").content
;; print response.index("click")
;; >>> 9949
;; hy_response_parse.hy
(import requests)
(setv response (. (requests.get "https://asciinema.org/api/asciicasts/17675") content))
(print (response.index "click"))
;; Traceback (most recent call last):
;; File "<input>", line 1, in <module>
;; UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 5337: ordinal not in range(128)
;; fix - wrap untrustable string in bytes.
;; Thanks @paultag
(print (response.index (bytes "click")))
;; EDIT ----- with CPython 3.4.0
;; Traceback (most recent call last):
;; File "<input>", line 1, in <module>
;; TypeError: Type str doesn't support the buffer API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment