vakdev / VakScript

Spaceglider for League of Legends.
163 stars 35 forks source link

autosmite.py not support non ASCII summoner names #5

Closed ruoxu233 closed 1 year ago

ruoxu233 commented 1 year ago

I tried this script in Taiwan server, but it couldn't run because the summoner name had Chinese characters in it. I discovered this error "UnicodeEncodeError: 'ascii' codec can't encode character '\u5716' in position 54: ordinal not in range(128)" from urlopen() function

    def get_damage(rawNames, url_request):
        spells = loads(urlopen(url_request).read())
        sp1, sp2 = spells["summonerSpellOne"], spells["summonerSpellTwo"]
        for v, v2 in zip(sp1.values(), sp2.values()):
            if v in rawNames:
                return rawNames[v]
            if v2 in rawNames:
                return rawNames[v2]

Use the quote () function to encode name and add the encoded string to the URL.This can ensure that the non -ascii characters in the URL are correctly processed.

from urllib.request import urlopen
from urllib.parse import quote

name = "名字" # non ASCII summoner names
name_encoded = quote(name)
url_request = f"https://127.0.0.1:2999/liveclientdata/activeplayername/{name_encoded}"
response = urlopen(url_request)
vakdev commented 1 year ago

Ty, I'll add it in next update!