ggtracker / sc2reader

Extracts gameplay information from Starcraft II replay files
http://pypi.python.org/pypi/sc2reader
MIT License
145 stars 144 forks source link

load_map=True results in URLError #140

Closed Volker-Weissmann closed 3 years ago

Volker-Weissmann commented 3 years ago

This works just fine:

import sc2reader
path = "/home/volker/Sync/DatenVolker/git/sc2stats/zipout/CN/Group A/1 TIME vs BreakingGG/Time vs BreakingGG G1.SC2Replay"
sc2reader.load_replay(path)

but this

#!/usr/bin/env python
import sc2reader

path = "/home/volker/Sync/DatenVolker/git/sc2stats/zipout/CN/Group A/1 TIME vs BreakingGG/Time vs BreakingGG G1.SC2Replay"
sc2reader.load_replay(path, load_map=True)

fails with the message

Traceback (most recent call last):
  File "/usr/lib/python3.9/urllib/request.py", line 1342, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/volker/Sync/DatenVolker/git/sc2stats/./extract.py", line 5, in <module>
    sc2reader.load_replay(path, load_map=True)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 85, in load_replay
    return self.load(Replay, source, options, **new_options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 143, in load
    return self._load(cls, resource, filename=filename, options=options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 152, in _load
    obj = cls(resource, filename=filename, factory=self, **options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/resources.py", line 307, in __init__
    self.load_map()
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/resources.py", line 447, in load_map
    self.map = self.factory.load_map(self.map_file, **self.opt)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 105, in load_map
    return self.load(Map, source, options, **new_options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 142, in load
    resource, filename = self._load_resource(source, options=options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 201, in _load_resource
    contents = self.load_remote_resource_contents(resource, **options)
  File "/home/volker/.local/lib/python3.9/site-packages/sc2reader/factories/sc2factory.py", line 185, in load_remote_resource_contents
    return urlopen(resource).read()
  File "/usr/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/usr/lib/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.9/urllib/request.py", line 1371, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.9/urllib/request.py", line 1345, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

I'm using Python 3.9.1. Both ipv4 and ipv6 internet is working.

Talv commented 3 years ago

It appears to be a replay from CN region. Which is not a problem on its own, but blizz quite recently migrated their "depot" to amazon S3, what also resulted in change of the domain names. It was fixed for US/EU/KR in https://github.com/ggtracker/sc2reader/commit/98eb2d90630fec4667bd63b22cc4559265767b98 However that fix does not account for CN - it currently points to a domain that doesn't exists, thus the error. And I think it was broken for CN even before that patch, lol.

Anyway, the correct URL for CN is http://cn-s2-depot.battlenet.com.cn/{1}.{2}

StoicLoofah commented 3 years ago

@Talv Seems like a solid diagnosis to me!

@Volker-Weissmann can you test that out and see if it works? If so, I would be happy to take a Pull Request fixing it!

Volker-Weissmann commented 3 years ago

url_template = "http://{0}-s2-depot.battlenet.com.cn/{1}.{2}"

does work.

Andrene commented 3 years ago

This should be safe to close now that the PR was merged.

HADB commented 3 years ago

Hi, PR #151 didn't fix this problem. It only add suffix '.cn' to the domain, but still unavailable. 'https://CN-s2-depot.classic.blizzard.com.cn' should be 'http://CN-s2-depot.battlenet.com.cn'.

Andrene commented 3 years ago

Woops, missed the difference in the url when I created the pr. Nice fix for the resources.py urls too!