problemlow
problemlow

Reputation: 61

Python requests html 403 response

Im using the requests module in python to try and make a search on the following webiste http://musicpleer.audio/, however this website appears to be blocking me as it issues nothing but a 403 when i attempt to access it, im wondering how i can get around this, ive tried sending it the user agent of my web browser(chrome) and it still returns error 403. any suggestions on how i could get around this an example of downloading a song from the site would be very helpful. Thanks in advance

My code:

import requests, os

def funGetList:
    start_path = 'C:/Users/Jordan/Music/' # current directory
    list = []
    for path,dirs,files in os.walk(start_path):
        for filename in files:
            temp = (os.path.join(path,filename))
            tempLen = len(temp)
            "print(tempLen)"
            iterate = 0
            list.append(temp[22:(len(temp))-4])

def funDownloadMP3:
    for i in list:
        print(i)

    payload = {'searchQuery': 'meme', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}
    url = 'http://musicpleer.audio/'
    print(requests.post(url, data=payload))

Upvotes: 0

Views: 5694

Answers (2)

AChampion
AChampion

Reputation: 30258

Putting the User-Agent in the headers seems to work:

In []:
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}
url = 'http://musicpleer.audio/'
r = requests.get('{}#!{}'.format(url, 'meme'), headers=headers)
r.status_code

Out[]:
200

Note: It looks like the search url is simple '#!<search-term>'

Upvotes: 1

sudo
sudo

Reputation: 943

HTML 403 Forbidden error code. The server might be expecting some more request headers like Host or Cookies etc. You might want to use Postman to debug it with ease

Upvotes: 0

Related Questions