smiley/steamapi

APIPrivate error thrown when querying a SteamUser

BenQuigley opened this issue · 18 comments

What am I doing wrong here?

>>> import steamapi
>>> steamapi.core.APIConnection(api_key="my API key")
# object gets created 
>>> steamapi.user.SteamUser(userurl='my userid`)
steamapi.errors.APIPRIVATE

`

This URL (from their docs) works, so I don't think the problem is with my Steam profile:

http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=[my API key]&steamids=[my steam ID])

Can you write down the exact code you ran (minus your key)?

That is the exact code I ran, from the readme. I left out the last '>>>' on the steamapiuser.SteamUser call; that was my input and this was the full result:

  File "main.py", line 19, in <module>
    main()
  File "main.py", line 15, in main
    steamapi.user.SteamUser(userurl=steam[1])
  File "c:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\s
teamapi-0.1-py3.5.egg\steamapi\user.py", line 118, in __init__
    response = APIConnection().call("ISteamUser", "ResolveVanityURL", "v0001", v
anityurl=userurl)
  File "c:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\s
teamapi-0.1-py3.5.egg\steamapi\core.py", line 437, in call
    errors.check(response)
  File "c:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\s
teamapi-0.1-py3.5.egg\steamapi\errors.py", line 106, in check
    raise APIPrivate()
steamapi.errors.APIPrivate

Well, it works on my end... Creating a APIConnection doesn't do anything server-side, so it could just be a bad key.

You can try creating an APIInterface and setting autopopulate to True to make it query the API itself:

steamapi.core.APIInterface(self, api_key="<KEY>", autopopulate=False)

It looks like passing an invalid key here fails the call. (With a APIPrivate error, so that might be the issue)

I just added (4446635) key validation to APIConnection and APIInterface. Can you try it again, but with validate_key=True in APIConnection?

After git pull --

>>> steam = (steam_id, api_key)
>>> steamapi.core.APIConnection(api_key=steam[0], validate_key=True)
>>> me = steamapi.user.SteamUser(userurl=steam[1])
Traceback (most recent call last):
  File "main.py", line 19, in <module>
    main()
  File "main.py", line 14, in main
    steamapi.core.APIConnection(api_key=steam[0], validate_key=True)
  File "C:\Users\BenQuigley \AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\decorators.py", l
ine 113, in __call__
    self._instance = self._decorated(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'validate_key'

It worked on my PC with a fresh install of Python 3. Did you reopen Python? (And ran setup.py install again if that's how you installed it)

Oh, I did not re-run the setup tool, one second.

Ah, see that's what I don't like about setup.py install (vs setup.py develop). It copies the .py files to your site-packages, making changes to the source folder useless. develop is more suited to a git clone (which just links to the code instead of copying it).

After re-running setup, errors out with three exceptions:

AttributeError: 'Singleton' object has no attribute '_instance'
steamapi.errors.APIPrivate: You have no permission to use this API, or your key may be invalid.
steamapi.errors.APIConfigurationError: This API key is invalid.

I have checked the API key, and it's exactly what is posted in my https://steamcommunity.com/dev/apikey page.

What triggers those exceptions? Can you please attach stack traces? Are you logging all exceptions thrown, including handled ones? Because the first & second exceptions -- if triggered from initializing APIConnection -- are caught & handled as part of the normal flow. (E.g.: _instance is created if it can't be found)

Sure:


C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\python.exe C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py
Traceback (most recent call last):
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\decorators.py", line 111, in __call__
    return self._instance
AttributeError: 'Singleton' object has no attribute '_instance'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 408, in __init__
    self.call("ISteamWebAPIUtil", "GetSupportedAPIList", "v1")
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 459, in call
    errors.check(response)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\errors.py", line 107, in check
    raise APIPrivate("You have no permission to use this API, or your key may be invalid.")
steamapi.errors.APIPrivate: You have no permission to use this API, or your key may be invalid.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py", line 19, in <module>
    main()
  File "C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py", line 14, in main
    steamapi.core.APIConnection(api_key=steam[0], validate_key=True)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\decorators.py", line 113, in __call__
    self._instance = self._decorated(*args, **kwargs)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 410, in __init__
    raise APIConfigurationError("This API key is invalid.")
steamapi.errors.APIConfigurationError: This API key is invalid.

Process finished with exit code 1

With validate_key=False:

C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\python.exe C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py
Traceback (most recent call last):
  File "C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py", line 19, in <module>
    main()
  File "C:/Users/BenQuigley/Dropbox/Projects/steamgames/main.py", line 15, in main
    me = steamapi.user.SteamUser(userurl=steam[1])
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\user.py", line 118, in __init__
    response = APIConnection().call("ISteamUser", "ResolveVanityURL", "v0001", vanityurl=userurl)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 459, in call
    errors.check(response)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\errors.py", line 107, in check
    raise APIPrivate("You have no permission to use this API, or your key may be invalid.")
steamapi.errors.APIPrivate: You have no permission to use this API, or your key may be invalid.

Process finished with exit code 1
Traceback (most recent call last):
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\decorators.py", line 111, in __call__
    return self._instance
AttributeError: 'Singleton' object has no attribute '_instance'

This is normal and happens when no APIConnection was initialized yet. (Even on first-init, the Singleton class tries to look for an existing one)

Traceback (most recent call last):
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 408, in __init__
    self.call("ISteamWebAPIUtil", "GetSupportedAPIList", "v1")
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\core.py", line 459, in call
    errors.check(response)
  File "C:\Users\BenQuigley\AppData\Local\Programs\Python\Python35\lib\site-packages\steamapi-0.1-py3.5.egg\steamapi\errors.py", line 107, in check
    raise APIPrivate("You have no permission to use this API, or your key may be invalid.")
steamapi.errors.APIPrivate: You have no permission to use this API, or your key may be invalid.

This is later caught by the validate_key=True flow and translated into a APIConfigurationError (the third exception).

It still looks like an API issue, and since it doesn't occur with my own key, it feels like an issue with your API key. Can you try to revoke & regenerate the key? I've had rare cases where Steam Community denied the same key steamcommunity.com/dev gave me. Regenerating fixed that for me.

Calling the same with validate_key just makes the same exception happen organically. Since we can't tell the key is invalid (because the error for "not allowed" & "bad key" is the same for most APIs), the APIPrivate error doesn't get translated.

That's a good idea. Thanks for the troubleshooting help.

Same error, though. I feel like this is probably something simple that I'm doing wrong... The API key is expected as a string, right? Mine is 32 characters, capital letters and numbers.

Yeah... I could try your key on my end and see what happens. (It's read-only anyway) You can DM it to me on Twitter.

It's working now; I think this must have been my user error. Thanks smiley.