From 69b9d71e8d5678dd47b32ed58ba3d8f8a4076581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6k=C3=A7e?= Date: Wed, 26 Oct 2022 17:36:35 +0300 Subject: [PATCH] fix: request without "user-agent" cause error due to cloudflare block --- turengcli/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/turengcli/cli.py b/turengcli/cli.py index 2baa916..56b266f 100644 --- a/turengcli/cli.py +++ b/turengcli/cli.py @@ -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"]