I was using the get function to print the data from a spreadsheet in Sheety but when I pressed the run button, it just said: 'Process finished with exit code 0' so why am I no getting the data printed out? Here is my code(I also want to put the code in a class):
Thanks
import requests
SHEETY_PRICES_ENDPOINT = 'https://docs.google.com/spreadsheets/d/1tHNqhwNfvixlV3Xc4-LHR0MgjHraNTpQk5dhNynM7wI/edit?usp=sharing'
class DataManager:
def get_destination_data(self):
response = requests.get(SHEETY_PRICES_ENDPOINT)
data = response.json()
print(data.text)
CodePudding user response:
Because you only defined a Class called DataManager that has a function called get_destination_data. You need to call the function to execute it. One way to do it would be to add a line after the class that calls the function. Also, respone cannot be converted to json like that. First get the text of the response. You should know if the your get function returns JSON or not, if yes, then it should be converted to JSON format.
First step to make this code to work would be to just get the response in text form. Then call the function. The working code then would look like this:
import requests
SHEETY_PRICES_ENDPOINT = 'https://docs.google.com/spreadsheets/d/1tHNqhwNfvixlV3Xc4-LHR0MgjHraNTpQk5dhNynM7wI/edit?usp=sharing'
class DataManager:
def get_destination_data(self):
response = requests.get(SHEETY_PRICES_ENDPOINT)
data = response.text
print(data)