Snippets

Lars Basic GeniusAPI GET request (search lyrics)

Updated by Lars

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
 import httplib, urllib, json,  random, sys
 
 def getData(auth_string):
-    conn = httplib.HTTPConnection("api.genius.com")
+    conn = httplib.HTTPSConnection("api.genius.com")
     request_uri = "/search/lyrics?q=You%20only%20get%20one%20shot" 
     headersMap = {
             "User-Agent": "CompuServe Classic/1.22",
Created by Lars

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+import httplib, urllib, json,  random, sys
+
+def getData(auth_string):
+    conn = httplib.HTTPConnection("api.genius.com")
+    request_uri = "/search/lyrics?q=You%20only%20get%20one%20shot" 
+    headersMap = {
+            "User-Agent": "CompuServe Classic/1.22",
+            "Accept": "application/json",
+            "Authorization": "Bearer " + auth_string
+    }
+    conn.request("GET", request_uri, headers=headersMap)
+    response = conn.getresponse()
+    ### Output the HTTP status code and reason text...
+    print response.status, response.reason
+    data = response.read()
+    result = json.loads(data)
+
+    print json.dumps(result, indent=4, sort_keys=True)
+
+getData("<Auth token here>")
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.