简体   繁体   中英

Python requests module works on my Windows laptop but not on AWS

I am newbie about python so if i missed something basics i am sorry. I have a code about getting information from a website and script works at vscode on my laptop but when i try same code with same loadings it doesnt work on AWS ubuntu and windows virtual computer. Here is the code:

url_arama = "https://www.sahibinden.com/otomobil/benzin,benzin-lpg/manuel/sahibinden?a4_max=250000&sorting=date_desc&a8=62068&viewType=Classic&a5_min=2004&price_min=25000&price_max=55000"
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}

page = requests.get(url_arama, headers=headers).text
soup = BeautifulSoup(page, "html.parser")    

response = page.json()
print(response)

and the is output:

Traceback (most recent call last):
  File "c:\Users\Administrator\Desktop\SahibindenBot\aaa.py", line 26, in <module>
    sahibinden()
  File "c:\Users\Administrator\Desktop\SahibindenBot\aaa.py", line 24, in sahibinden
    response = page.json()
AttributeError: 'str' object has no attribute 'json'

i tried to reach google it works but thie website doesnt work why is that?

AttributeError: 'str' object has no attribute 'json'

Try this:

import json

response = json.loads(page)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM