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

Paging through list of pledges: extract_cursor -> "Provided cursor path did not result in a link" #27

Open
sebastienvercammen opened this issue Oct 31, 2018 · 0 comments

Comments

@sebastienvercammen
Copy link

sebastienvercammen commented Oct 31, 2018

Using: https://docs.patreon.com/?python#paging-through-a-list-of-pledges

import patreon

access_token = '...' # your Creator Access Token
api_client = patreon.API(access_token)

# Get the campaign ID
campaign_response = api_client.fetch_campaign()
campaign_id = campaign_response.data()[0].id()

# Fetch all pledges
all_pledges = []
cursor = None
while True:
    pledges_response = api_client.fetch_page_of_pledges(campaign_id, 25, cursor=cursor)
    pledges += pledges_response.data()
    cursor = api_client.extract_cursor(pledges_response)
    if not cursor:
        break

Error:

Traceback (most recent call last):
  File ".\start.py", line 45, in <module>
    main()
  File ".\start.py", line 28, in main
    get_all_data(ACCESS_TOKEN)
  File "patreonapi.py", line 117, in get_all_data
    get_pledge_data(api_client, campaign.patreon_id)
  File "patreonapi.py", line 90, in get_pledge_data
    cursor = api_client.extract_cursor(pledges_response)
  File "C:\Python27\lib\site-packages\patreon\api.py", line 74, in extract_cursor
    'Provided cursor path did not result in a link', current_dict
Exception: ('Provided cursor path did not result in a link', u'https://www.patreon.com/api/oauth2/api/campaigns/<removed>/pledges?page%5Bcount%5D=10&sort=created&page%5Bcursor%5D=2017-12-03T18%3A06%3A42.344287%2B00%3A00')

Related to #19, which was apparently solved in #20, reverted in #21 and a next mention of six in #22 .

Environment:

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32

PS C:\Users\Seb> [Environment]::OSVersion
Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.17134.0 Microsoft Windows NT 10.0.17134.0

Workaround as described in #19 still works:

Replace:

cursor = api_client.extract_cursor(pledges_response)

With:

from urlparse import urlparse, parse_qs

# Temporary workaround until Patreon fixes the issue.
next_link = pledges_response.json_data.get('links', {}).get('next')

if not next_link:
    break

query = urlparse(next_link).query
parsed_qs = parse_qs(query)
cursor = parsed_qs['page[cursor]'][0]
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

No branches or pull requests

1 participant