upbit / pixivpy

Pixiv API for Python
https://pypi.org/project/PixivPy3/#files
The Unlicense
1.8k stars 148 forks source link

Demo example isn't working #150

Closed MOHOAzure closed 3 years ago

MOHOAzure commented 4 years ago

The demo example isn't working. Authentication seems required.

from pixivpy3 import *

api = AppPixivAPI()
# api.login("username", "password")   # Not required

# get origin url
json_result = api.illust_detail(59580629)
illust = json_result.illust
print(">>> origin url: %s" % illust.image_urls['large'])

# get ranking: 1-30
# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]
json_result = api.illust_ranking('day')
for illust in json_result.illusts:
    print(" p1 [%s] %s" % (illust.title, illust.image_urls.medium))

# next page: 31-60
next_qs = api.parse_qs(json_result.next_url)
json_result = api.illust_ranking(**next_qs)
for illust in json_result.illusts:
    print(" p2 [%s] %s" % (illust.title, illust.image_urls.medium))

Error message

raise PixivError('Authentication required! Call login() or set_auth() first!')
pixivpy3.utils.PixivError: Authentication required! Call login() or set_auth() first!
upbit commented 4 years ago

Emm, illust_ranking may need auth by default If you think Pixiv not check auth in the interface, try api.illust_ranking(..., req_auth=False)

MOHOAzure commented 4 years ago

The authentication is not only required by illust_ranking function. The above functions all have the same problem.

Besides, I got another error after trying api.illust_ranking(..., req_auth=False).

for illust in json_result.illusts:
TypeError: 'NoneType' object is not iterable
upbit commented 4 years ago

Most APIs on Pixiv require authentication, so we set req_auth=True by default.

I have not seen the request method without auth on the app. The return is None, it is probably because Pixiv requires authentication, but you did not provide it. (Try login with your own account) If you find out some interface can success access without auth, you can let me know.

MOHOAzure commented 4 years ago

Understood. But I wonder why demo example presents that login is not required?

# api.login("username", "password")   # Not required

Or it means something else?

upbit commented 4 years ago

Well, some interfaces of the early client did not require token, but sometime later Pixiv changed its strategy.

Currently known, only api.showcase_article() (the function to pull the background image before login), does not require authentication.