Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG -- Requiring name argument in StackAPI makes "/users/{id}/network-activity" endpoint inaccessible #52

Closed
it176131 opened this issue May 2, 2024 · 2 comments · Fixed by #53

Comments

@it176131
Copy link
Contributor

it176131 commented May 2, 2024

MREs

While trying to access the "/users/{id}/network-activity" endpoint I ran into a StackAPIError.

from stackapi import StackAPI

my_acct_id = 8698988

# Providing `name` argument raises `StackAPIError`.
SITE = StackAPI(name="stackoverflow")
SITE.fetch(endpoint="users/{id}/network-activity", id=my_acct_id)
---------------------------------------------------------------------------
StackAPIError                             Traceback (most recent call last)
Cell In[6], line 3
      1 # Providing `name` argument raises `StackAPIError`.
      2 SITE = StackAPI(name="stackoverflow")
----> 3 SITE.fetch(endpoint="users/{id}/network-activity", id=8698988)

File ~\.env\Lib\site-packages\stackapi\stackapi.py:211, in StackAPI.fetch(self, endpoint, page, key, filter, **kwargs)
    209     code = response["error_name"]
    210     message = response["error_message"]
--> 211     raise StackAPIError(self._previous_call, error, code, message)
    212 except KeyError:
    213     pass  # This means there is no error

StackAPIError: ('https://api.stackexchange.com/2.3/users/8698988/network-activity/?pagesize=100&page=1&filter=default&site=stackoverflow', 400, 'bad_parameter', 'This method does not accept a `site` parameter')

After reading the Usage of /users/{id}/network-activity page, the error made more sense—I shouldn't supply a site parameter to the URL. I took this to mean not setting the name argument in StackAPI, but this raises a ValueError.

# No site provided raises ValueError.
SITE = StackAPI()
SITE.fetch(endpoint="users/{id}/network-activity", id=my_acct_id)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 6
      3 my_acct_id = 8698988
      5 # No site provided raises ValueError.
----> 6 SITE = StackAPI()
      7 SITE.fetch(endpoint="users/{id}/network-activity", id=my_acct_id)

File ~\.env\Lib\site-packages\stackapi\stackapi.py:60, in StackAPI.__init__(self, name, version, base_url, **kwargs)
     32 """
     33 The object used to interact with the Stack Exchange API
     34 
   (...)
     57     a user, to grant more permissions (such as write access)
     58 """
     59 if not name:
---> 60     raise ValueError("No Site Name provided")
     62 self.proxy = kwargs.get("proxy", None)
     63 self.max_pages = kwargs.get("max_pages", 5)

ValueError: No Site Name provided

Proposal

I believe this may be an unintended bug, and if so I'd be willing to submit a PR.

Version Info

Python

3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)]

StackAPI

Name: StackAPI
Version: 0.3.0
Summary: Library for interacting with the Stack Exchange API
Home-page: https://github.com/AWegnerGitHub/StackAPI
Author: Andrew Wegner
Author-email: [email protected]
License: MIT
Location: ~\.env\Lib\site-packages
Requires: requests, six
Required-by: 
@AWegnerGitHub
Copy link
Owner

Hey @it176131. Thanks for the report! If you have a PR, I'd be happy to look it over and merge it in.

@it176131
Copy link
Contributor Author

it176131 commented May 2, 2024

Hey @it176131. Thanks for the report! If you have a PR, I'd be happy to look it over and merge it in.

Rock on! I'll get to work and link back to this issue.

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

Successfully merging a pull request may close this issue.

2 participants