Skip to content

Commit d6ae474

Browse files
committed
Fixed errors due to too many redirects
1 parent b528fe0 commit d6ae474

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

PyDictAPI/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@
1111

1212
def handleRequests(query):
1313
'''Returns HTML document'''
14+
URL = 'https://www.dictionary.com/browse/{0}'.format(query)
1415
try:
15-
response = requests.get(f'https://www.dictionary.com/browse/{query}').text
16-
return response
16+
return requests.get(URL, allow_redirects=False).text
1717
except Exception:
1818
raise ConnectionError("Error occured while fetching data from the web, please try checking the internet connection.")
1919

2020
def ParseUsage(query):
2121
'''Returns HTML document'''
22+
URL = 'https://www.lexico.com/en/definition/{0}'.format(query)
2223
try:
23-
response = requests.get(f'https://www.lexico.com/en/definition/{query}').text
24+
response = requests.get(URL, allow_redirects=False).text
2425
return response
2526
except Exception:
2627
raise ConnectionError("Error occured while fetching data from the web, please try checking the internet connection.")
2728

2829
def ParseSynonymsAndAntonyms(query):
2930
'''Returns HTML document'''
31+
URL = 'https://www.thesaurus.com/browse/{0}'.format(query)
3032
try:
31-
response = requests.get(f'https://www.thesaurus.com/browse/{query}').text
33+
response = requests.get(URL, allow_redirects=False).text
3234
return response
3335
except Exception:
3436
raise ConnectionError("Error occured while fetching data from the web, please try checking the internet connection.")

0 commit comments

Comments
 (0)