Yagel
Yagel

Reputation: 1312

Forbidden (403) when requesting a page via python3

I want to request this via python3.

This is the code:

import requests
bizportal_company_url = "https://www.bizportal.co.il/realestates/quote/generalview/373019"
self.page = requests.get(self.bizportal_company_url)

and I get:

<Response [403]>

When I add verify=False to the get command, I get:

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
<Response [403]>

How can I fix it? When I access the url there is no password or anything.

Upvotes: 0

Views: 450

Answers (1)

baduker
baduker

Reputation: 20052

You might be missing a few things in your code.

Try this:

import requests

headers = {
    "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}

session = requests.Session()
response = session.get("https://www.bizportal.co.il", headers=headers)

url = "https://www.bizportal.co.il/realestates/quote/generalview/373019"
print(session.get(url, headers=headers).status_code)

This should print:

200

Which basically means the request has been successful.

Upvotes: 1

Related Questions