第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

運行 urllib 審查請求時引發(fā)無效 URL 錯誤

運行 urllib 審查請求時引發(fā)無效 URL 錯誤

炎炎設(shè)計 2022-06-14 16:28:14
我的代碼如下:import urllib.request as urllibdef read_text():    quotes = open(r"C:\Users\hjayasinghe2\Desktop\Hasara Work\Learn\demofile.txt")    contents_of_file = quotes.read()    print(contents_of_file)    quotes.close()    check_pofanity(contents_of_file)def check_pofanity(text_to_check):    connection = urllib.urlopen("http://www.wdyl.com/profanity?q= " + text_to_check)    output = connection.read()    print(output)    connection.close()read_text()我得到的錯誤是這樣的:Traceback (most recent call last):  File "C:/Users/hjayasinghe2/Desktop/Hasara Work/Learn/check_profanity.py", line 16, in <module>    read_text()  File "C:/Users/hjayasinghe2/Desktop/Hasara Work/Learn/check_profanity.py", line 8, in read_text    check_pofanity(contents_of_file)  File "C:/Users/hjayasinghe2/Desktop/Hasara Work/Learn/check_profanity.py", line 11, in check_pofanity    connection = urllib.urlopen("http://www.wdyl.com/profanity?q= " + text_to_check)  File "C:\Users\hjayasinghe2\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 222, in urlopen    return opener.open(url, data, timeout)  File "C:\Users\hjayasinghe2\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 525, in open    response = self._open(req, data)  File "C:\Users\hjayasinghe2\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 543, in _open    '_open', req)
查看完整描述

1 回答

?
慕娘9325324

TA貢獻1783條經(jīng)驗 獲得超4個贊

您需要對查詢進行 URL 編碼。嘗試類似:


import urllib, urllib.parse

url = "http://www.wdyl.com/profanity?q=" + urllib.parse.quote(text_to_check)

connection = urllib.urlopen(url)

見https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote


查看完整回答
反對 回復(fù) 2022-06-14
  • 1 回答
  • 0 關(guān)注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號