Skip to content

Commit

Permalink
fix: request without "user-agent" cause error due to cloudflare block
Browse files Browse the repository at this point in the history
  • Loading branch information
agmmnn committed Oct 26, 2022
1 parent 740a331 commit 69b9d71
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion turengcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def __init__(self, word, args):
def req(self):
url = "http://ws.tureng.com/TurengSearchServiceV4.svc/Search"
payload = {"Term": self.word}
headers = {"Content-Type": "application/json", "Origin": "tureng.com"}
user_agent = "Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36"
headers = {
"Content-Type": "application/json",
"Origin": "tureng.com",
"User-Agent": user_agent,
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
self.j = json.loads(response.text) # encoding="utf8"
self.rslt = self.j["MobileResult"]["Results"]
Expand Down

0 comments on commit 69b9d71

Please sign in to comment.