requests.exceptions.MissingSchema: 无效 URL Python API 获取请求

requests.exceptions.MissingSchema: Invalid URL Python API Get request

我正在尝试通过下面的 URL 使用 get 请求提取数据,但出现以下错误。

我不明白 URL 有什么问题。

如有任何帮助,我们将不胜感激

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('admin@abc.com', 'Summer2020')) 
print(response.content)

错误

引发MissingSchema(错误) requests.exceptions.MissingSchema:无效 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':未提供架构。也许你的意思是 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?

这可能是因为您将整个 URL 传递给了 urllib.parse.quote 函数。尝试仅将参数传递给 urllib.parse.quote 或使用 requests 参数,如下例所示:

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('admin@abc.com', 'Summer2020')

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