Reputation: 41
I'm trying to get the html object of a local sharepoint page using python and when I try to send request I get 403 error. Below is the code which I'm using.
import requests from requests_ntlm import HttpNtlmAuth request=requests.get("https://my.mycompany.net/Profile.aspx?acname=i%3A0%23.f%7Cmembership%7Cparametertext%40company.net", auth=HttpNtlmAuth('domain\userid','mypassword')) print(request)
can you say why I'm getting 403 error and Is there any other way to get the html of sharepoint page? I tried simple request as below using beautifulsoap but still I get error 403.
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
My goal is to get data on the page based on class name, ID or Tag.
Please let me know how to resolve this issue.
Upvotes: 0
Views: 1527
Reputation: 4228
You might need to enable Basic authentication on your webapplication. Open the Internet Information Services Manager and find your webapplication under ’sites’ to the left. Dubbleclick on the Authentication, click on Basic Authentication and enable. And use the following code to get the entire page’s HTML.
import requests
from requests.auth import HTTPBasicAuth
r = requests.get("http://example", auth=HTTPBasicAuth('someUser', 'somePassword'), headers=headers)
print r.status_code
print r.content
Refer to: Using Python to request data from SharePoint via REST
Upvotes: 0