0

I've just started learning Python. I got this error in the code I used. I would be glad if you help. Thanks

import requests
import pandas as pd
headers = {
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'en-US,en;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Referer': 'http://www.wikipedia.org/',
    'Connection': 'keep-alive',
}

response = requests.get('https://www.ebooks.com/en-tr/subjects/computers/?ResultOrder=Popularity/', headers=headers)

response.status_code

response.json() # the mistake is here

View error

Edit; I found the solution. When I used the params parameter in the requests get function, the problem was resolved and I was able to output as jason without any problems.

    params = (
    ('subjectId', '13'),
    ('pageNumber', '1'),
    ('countryCode', 'DE'),
)
  • Welcome to Stack Overflow! Please take the [tour], have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Please post code, error messages, markup, and other textual information **as text**, not as a *picture* of text. Why: http://meta.stackoverflow.com/q/285551/157247 – T.J. Crowder Jan 18 '22 at 17:02
  • In your own words, when you make this request, why do you think you should get JSON data back? When you go to that URL in a web browser, do you see JSON? – Karl Knechtel Jan 18 '22 at 17:32
  • I'm watching a training set. The instructor had done it this way – Abdurrahman AY Jan 18 '22 at 17:41
  • I found the solution. When I used the params parameter in the requests get function, the problem was resolved and I was able to output as jason without any problems. – Abdurrahman AY Jan 18 '22 at 19:35
  • Please, next time, search for the error you get online. This question comes up daily. As a new user here, also take the [tour] and read [ask]. – Ulrich Eckhardt Jan 18 '22 at 19:40

1 Answers1

1

The response content is HTML, not JSON. You can view it with response.content or response.text.

liveware
  • 72
  • 5