Fixed strange issue with urllib trying to connect on IPv4

This commit is contained in:
Krateng 2019-02-15 15:18:57 +01:00
parent d481746514
commit 3a06123255
7 changed files with 21 additions and 19 deletions

View File

@ -11,7 +11,7 @@ def replacedict(keys,dbport):
imgurl = info.get("image")
#desc = info.get("info")
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
scrobbles = str(db_data["scrobbles"])
pos = "#" + str(db_data["position"])
@ -29,7 +29,7 @@ def replacedict(keys,dbport):
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?artist=" + urllib.parse.quote(keys["artist"]))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/tracks?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
if db_data["list"] != []: maxbar = db_data["list"][0]["scrobbles"]

View File

@ -4,7 +4,7 @@ from htmlgenerators import artistLink
def replacedict(keys,dbport):
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/issues")
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/issues")
db_data = json.loads(response.read())
i = 0

View File

@ -11,7 +11,7 @@ def replacedict(keys,dbport):
limitkeys = pickKeys(keys,"artist","title","associated")
# Get scrobble data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys,timekeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys,timekeys))
db_data = json.loads(response.read())
scrobbles = db_data["list"]
@ -24,7 +24,7 @@ def replacedict(keys,dbport):
elif keys.get("artist") is not None:
limitstring += "by " + artistLink(keys.get("artist"))
if keys.get("associated") is not None:
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
moreartists = db_data["associated"]
if moreartists != []:

View File

@ -26,7 +26,8 @@ def replacedict(keys,dbport):
# get chart data
# artists
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists")
print("REQUESTING " + "http://[::1]:" + str(dbport) + "/charts/artists")
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/artists")
db_data = json.loads(response.read())
charts = db_data["list"][:max_show]
topartist = charts[0]["artist"]
@ -40,7 +41,7 @@ def replacedict(keys,dbport):
# tracks
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks")
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/tracks")
db_data = json.loads(response.read())
charts = db_data["list"][:max_show]
@ -55,7 +56,7 @@ def replacedict(keys,dbport):
# get scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?max=50")
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?max=50")
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbletrackobjects = scrobblelist #ignore the extra time attribute, the format should still work
@ -70,23 +71,24 @@ def replacedict(keys,dbport):
# get stats
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=today")
response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=today")
stats = json.loads(response.read())
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=month")
response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=month")
stats = json.loads(response.read())
scrobbles_month = "<a href='/scrobbles?since=month'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=year")
response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=year")
stats = json.loads(response.read())
scrobbles_year = "<a href='/scrobbles?since=year'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles")
response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles")
stats = json.loads(response.read())
scrobbles_total = "<a href='/scrobbles'>" + str(stats["amount"]) + "</a>"
t1.join()
t2.join()
t3.join()

View File

@ -11,7 +11,7 @@ def replacedict(keys,dbport):
limitkeys = pickKeys(keys)
# get chart data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
charts = db_data["list"][:50]
topartist = charts[0]["artist"]
@ -20,7 +20,7 @@ def replacedict(keys,dbport):
imgurl = info.get("image")
# get total amount of scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)

View File

@ -11,7 +11,7 @@ def replacedict(keys,dbport):
limitkeys = pickKeys(keys,"artist")
# get chart data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + keysToUrl(timekeys,limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/tracks?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
charts = db_data["list"][:50]
limitstring = ""
@ -30,7 +30,7 @@ def replacedict(keys,dbport):
# get total amount of scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)

View File

@ -12,13 +12,13 @@ def replacedict(keys,dbport):
imgurl = info.get("image")
desc = info.get("info")
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/trackinfo?" + keysToUrl(limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/trackinfo?" + keysToUrl(limitkeys))
db_data = json.loads(response.read())
scrobblesnum = str(db_data["scrobbles"])
pos = "#" + str(db_data["position"])
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys))
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys))
db_data = json.loads(response.read())
scrobbles = db_data["list"]