lucjon / Py-StackExchange

A Python binding for the StackExchange API
http://stackapps.com/questions/198/py-stackexchange-an-api-wrapper-for-python
BSD 3-Clause "New" or "Revised" License
228 stars 76 forks source link

Site.users_by_name is defunct #74

Open f4lco opened 3 years ago

f4lco commented 3 years ago

I do appreciate the shorthand users_by_name. However, users_by_name results in a bad request. See below example what does not work, and what my current workaround looks like:

>>> import stackexchange as se
>>> site = se.Site(se.StackOverflow)
>>> site.users_by_name('f4lco')  # This does not work
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/site.py", line 230, in users_by_name
    return self.users(**kw)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/site.py", line 226, in users
    return self._get(User, ids, 'users', kw)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/site.py", line 213, in _get
    return self.build(root, typ, coll, kw)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/site.py", line 190, in build
    json = self._request(url, kw)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/site.py", line 161, in _request
    json, info = request_mgr.json_request(url, new_params)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/web.py", line 163, in json_request
    req = self.request(to, params)
  File "/Users/.../py3.9/lib/python3.9/site-packages/stackexchange/web.py", line 150, in request
    raise StackExchangeError(error_ob.get('error_id', StackExchangeError.UNKNOWN), error_ob.get('error_name'), error_ob.get('error_message'))
stackexchange.core.StackExchangeError: 400 [bad_parameter]: Invalid filter specified
>>> site.users(inname='f4lco')  # This does work, but it's not really obvious
(<User 'f4lco' (345057) @ 10e9d9c40>, <User 'wiref4lcon' (13192697) @ 10e9eca90>)

I'm running OS X, Python 3.9, and Py-StackExchange 2.2.7.