Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Is i possible for iter_lines to show all lines?

unmur

New Coder
This is only giving me one line back, I want all lines back. Is there a way to have iter_lines show all lines? Thanks.

Python:
#import modules
import requests
import json
import re

#retrieve lichess games for a specific user
def get_lichess_games(username):

    api_session = requests.Session()
    api_headers = {
        'Authorization' : 'Bearer CZfakeeeeBWo',
        'Accept'        : 'application/x-ndjson',
    }

    with api_session.get(f'https://lichess.org/api/games/user/{username}', headers=api_headers, stream=True) as response:
        for line in response.iter_lines():
            if line:
                test = json.loads(line.decode('utf-8'))
            return test

data = get_lichess_games(username='putin')
print(data)
 
Hey :D

If you have the Modules file handy i can have alook for you and test it my end :D Looking through my first question would be to print the api_session.get(f'https://lichess.org/api/games/user/{username}', headers=api_headers, stream=True) and make sure you are in fact getting back more then one record.

Also i haven't played around with .iter_lines() much but from my understanding that reads one line at a time from a request right? So if that's the case then your for loop is working, you might have to .append the data into an array and then do for line in array.
 

Buy us a coffee!

Back
Top Bottom