2
votes

I am trying to pull the data using get request through the below URL and I'm getting below error.

I'm not understanding what is the issue with the URL.

Any help would be appreciated

import requests
from requests.auth import HTTPBasicAuth 
import json
import urllib.parse

url = """https://msi.abc.com/admin/ui/feedbackCSV/reports
/5d14de32309baf0001501fb7 ?reports[]=pageviews&reports[]=
searches&from=Oct 1 2020&to=Oct 2 2020"""

encode_url = urllib.parse.quote(url,encoding='utf-8')

response = requests.get(encode_url,auth = HTTPBasicAuth('[email protected]', 'Summer2020')) 
print(response.content)

Error

raise MissingSchema(error) requests.exceptions.MissingSchema: Invalid URL 'https%3A%2F%2Fmsi.abc.com%2Fadmin%2Fui%2FfeedbackCSV%2Freports%0D%0A%2F5d14de32309baf0001501fb7%20%3Freports%5B%5D%3Dpageviews%26reports%5B%5D%3D%0D%0Asearches%26from%3DOct%201%202020%26to%3DOct%202%202020': No schema supplied. Perhaps you meant http:https%3A%2F%2Fmsi.abc.com%2Fadmin%2Fui%2FfeedbackCSV%2Freports%0D%0A%2F5d14de32309baf0001501fb7%20%3Freports%5B%5D%3Dpageviews%26reports%5B%5D%3D%0D%0Asearches%26from%3DOct%201%202020%26to%3DOct%202%202020?

1
How is the Output URL should look like? Can you put an example?Harshana Serasinghe
@HarshanaSerasinghe I have this url msi.abc.com/admin/ui/feedbackCSV/reports /5d14de32309baf0001501fb7 ?reports[]=pageviews&reports[]= searches&from=Oct 1 2020&to=Oct 2 2020 i'm encoding this url to parse special char in uri using urllib.parse.quote(url,encoding='utf-8')Rahul
Okay. Is the host name 'msi.abc.com' a correct one or you just add it as an example?Harshana Serasinghe
I added it as an example.Rahul

1 Answers

2
votes

This might be due to that you pass the whole URL to the urllib.parse.quote function. Try passing the params only to the urllib.parse.quote or use requests params like in the below example:

import requests
from requests.auth import HTTPBasicAuth 
import json
import urllib.parse

url = "https://msi.abc.com/admin/ui/feedbackCSV/reports/5d14de32309baf0001501fb7"
payload = {'reports[]':'pageviews', 'reports[]':'searches','from':'Oct 1 2020', 'to':'Oct 2 2020' }

authParams = HTTPBasicAuth('[email protected]', 'Summer2020')

response = requests.get(url,params=payload, auth =authParams ) 
print(response.content)