GAE Python網址提取引發InvalidURLError,而同一個網址與Postman(Google Chrome應用)完美配合。GAE Python網址提取InvalidURLError
CODE
url = "https://abcdefgh:[email protected]n/v1/Accounts/abcdefgh/Sms/send"
form_fields = {
"From": "08039511111",
"To": "+919844100000",
"Body": "message for you"
}
form_data = urllib.urlencode (form_fields)
try:
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded' }
)
logging.info ("result = ["+repr (result)+"] ")
except Exception:
logging.error ("Exception. ["+traceback.format_exc()+"] ")
的輸出日誌
2016-01-21 15:48:23.368 +0530 E Exception. [
Traceback (most recent call last): File "main.py", line 27, in get method=urlfetch.POST,
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 271, in fetch return rpc.get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 613, in get_result return self.__get_result_hook(self)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 389, in _get_fetch_result 'Invalid request URL: ' + url + error_detail) InvalidURLError: Invalid request URL: https://abcdefgh:[email protected]n/v1/Accounts/abcdefgh/Sms/send ]
出於安全目的,我已經在類似的不同字符的URL替換敏感文字。
感謝丹。我發現了問題和解決方案。 我們需要使用標題指定HTTP認證信息。 urlfetch.make_fetch_call(RPC, URL, 方法= urlfetch.POST, 頭= { 「授權」: 「基本%的」 %base64.b64encode(URL_USERNAME + 「:」 + URL_PASSOWRD)}, ) – gsinha