Last active
August 29, 2015 14:17
-
-
Save taddeimania/d6f4a5dbd4755a75f53d to your computer and use it in GitHub Desktop.
Hy throwing error parsing response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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