Skip to content

Instantly share code, notes, and snippets.

@icehongssii
Last active January 26, 2019 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icehongssii/1ff1dae65edd2cf236f92765588a4671 to your computer and use it in GitHub Desktop.
Save icehongssii/1ff1dae65edd2cf236f92765588a4671 to your computer and use it in GitHub Desktop.
import requests
import json
def sendRequest(url):
res = requests.get(url)
contents = res.content.decode('utf-8')
# python2에서는 contents = res.content만 적어도 됩니다.
# python2에서는 res.content가 string으로 오지만
# python3에서는 byte로 오기 때문에 디코딩이 필요합니다.
# 대부분의 api는 json으로 반환되기 때문에 곧바로 json 라이브러리를 이용해 로드합니다
json_contents = json.loads(contents)
return json_contents
if __name__ == "__main__":
symbol_endpoint= "https://www.bitmex.com/api/v1/instrument/active"
res = sendRequest(symbol_endpoint)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment