thanks you very much. it has a “
u200b
” follow the.com
. “u200b
” is an invisable character. the reason is i copy the url from the website.but something interesting i found: if i use
pip install requests==2.21.0
(old version), it will not except this err. only use new version it will err.
InvalidURL: Failed to parse URL, some url will except this error while some other url wouldn’t.
already upgrade urllib3
and requests
err
urllib3.exceptions.LocationParseError: Failed to parse: https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey requests.exceptions.InvalidURL: Failed to parse: https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey
env
Python 3.8.6 (tags/v3.8.6:db45529) [MSC v.1927 64 bit (AMD64)] on win32 PS C:Windowssystem32> python -m pip install --upgrade urllib3 Requirement already satisfied: urllib3 in c:python38libsite-packages (1.26.8) PS C:Windowssystem32> python -m pip install --upgrade requests Requirement already satisfied: requests in c:python38libsite-packages (2.27.1) Requirement already satisfied: charset-normalizer~=2.0.0 in c:python38libsite-packages (from requests) (2.0.5) Requirement already satisfied: idna<4,>=2.5 in c:python38libsite-packages (from requests) (3.2) Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:python38libsite-packages (from requests) (1.26.8) Requirement already satisfied: certifi>=2017.4.17 in c:python38libsite-packages (from requests) (2021.5.30)
code
import requests url='https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey' #res=requests.post(url) res=requests.post(str(url))
error log
Traceback (most recent call last): File "C:Python38libsite-packagesrequestsmodels.py", line 384, in prepare_url scheme, auth, host, port, path, query, fragment = parse_url(url) File "C:Python38libsite-packagesurllib3utilurl.py", line 394, in parse_url return six.raise_from(LocationParseError(source_url), None) File "<string>", line 3, in raise_from urllib3.exceptions.LocationParseError: Failed to parse: https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:/test.py", line 3, in <module> res=requests.post(str(url)) File "C:Python38libsite-packagesrequestsapi.py", line 117, in post return request('post', url, data=data, json=json, **kwargs) File "C:Python38libsite-packagesrequestsapi.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:Python38libsite-packagesrequestssessions.py", line 515, in request prep = self.prepare_request(req) File "C:Python38libsite-packagesrequestssessions.py", line 443, in prepare_request p.prepare( File "C:Python38libsite-packagesrequestsmodels.py", line 318, in prepare self.prepare_url(url, params) File "C:Python38libsite-packagesrequestsmodels.py", line 386, in prepare_url raise InvalidURL(*e.args) requests.exceptions.InvalidURL: Failed to parse: https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey
Advertisement
Answer
There’s a typo, or invalid invisible character in your url. please copy from my code:
url='https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=samplekey'