Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Should check status code from requests.get() first in download_mod() #7

Closed
Arnavion opened this issue Sep 25, 2016 · 3 comments
Closed

Comments

@Arnavion
Copy link

Arnavion commented Sep 25, 2016

I ran fac install hacked-splitters and it failed with:

Traceback (most recent call last):
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\gtk-build\python-3.5\Win32\Scripts\fac.exe\__main__.py", line 9, in <module>
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\site-packages\fac\main.py", line 84, in main
    args.run(args)
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\site-packages\fac\commands\install.py", line 158, in run
    self.manager.install_mod(release, unpack=args.unpack)
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\site-packages\fac\mods.py", line 476, in install_mod
    self.download_mod(release, tmp_file)
  File "c:\programdata\chocolatey\lib\python3-x86_32\tools\lib\site-packages\fac\mods.py", line 515, in download_mod
    len(data), release.file_size
Exception: Downloaded file has incorrect size (0), expected 40119.

I added a print('%s' % req) in download_mod and get <Response [403]>. So basically the download request returned a 0-byte 403 response. You should probably also verify that the response status code is 200 before data = req.content, etc

(I'm still investigating why I'm getting a 403 there at all... The 403 is because this is a new account and I haven't connected it to my Steam account yet. Logging in to mods.factorio.com in a web browser gives me This account doesn't have a sufficient membership. If you bought the game on Steam, you need to connect your Steam account to your factorio.com account.)

@mickael9
Copy link
Owner

You can use -v for requests debugging :)

I'm not having this issue, I suspect the 403 error is because your token or username is invalid (from player-data.json)
Are you able to download mods from the game?

Anyway, I'll add some error handling so that invalid error codes are raised as HTTPError

@Arnavion
Copy link
Author

See edit to the OP :)

Anyway, I'll add some error handling so that invalid error codes are raised as HTTPError

Yeah, that's what I was asking for. Otherwise there's the possibility a non-200 response has the same content length as the actual mod file, and fac install won't notice.

@mickael9
Copy link
Owner

mickael9 commented Sep 25, 2016

There's no way it wouldn't fail later in the process anyway, since the zip file is opened and info.json is read before the zip gets saved.

Anyway, I added some proper error messages for both the "already logged in with no game ownership" and also added the require_ownership=true parameter which the game uses on login. This is what it looks like now:

$ fac install yarm
Installing: YARM 0.7.107...
Downloading: https://mods.factorio.com/api/downloads/data/mods/187/YARM_0.7.107.zip...
Authentification error when downloading mod. Please login again.
You need a Factorio account to download mods.
Please provide your username and password to authenticate yourself.
Your username and token (NOT your password) will be stored so that you only have to enter it once
This uses the exact same method used by Factorio itself

Username [mickael9-test]:  
Password (not shown):
Ownership error: Your factorio account doesn't own the game.
Please buy the game or link your Steam account if you have bought the game from Steam.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants