when i run get_word
function, i will get this error:
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
import requests
base_url = "https://www.ldoceonline.com/dictionary/"
def get_word(word: str):
return requests.get(base_url word)
Please Answer this problem!
CodePudding user response:
It works for me after I added a User-Agent
header
import requests
base_url = "https://www.ldoceonline.com/dictionary/"
def get_word(word: str):
return requests.get(base_url word, headers={"User-Agent":"Mozilla/5.0"})
response = get_word('apple')
print(response.text)