Skip to content

Commit

Permalink
Merge pull request #13 from moxw/fix/login
Browse files Browse the repository at this point in the history
fix(helper.py): add user-agent in session headers
  • Loading branch information
mr-karan authored Aug 15, 2023
2 parents 3b19171 + 5802382 commit 7d4a596
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions swiggy_analytics/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
get_scores, get_weekday_name, save_config)

session = requests.Session()

session.headers = {
"user-agent": (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"
" Chrome/115.0.0.0 Safari/537.36"
)
}

def fetch_orders_info(orders):
"""
Expand Down Expand Up @@ -128,7 +133,6 @@ def perform_login():

otp_response = session.post(SWIGGY_SEND_OTP_URL, headers={'content-type': 'application/json',
'Cookie':'__SW={}'.format(sw_cookie),
'User-Agent': 'Mozilla/Gecko/Firefox/65.0'
},
json={"mobile": username, '_csrf': csrf_token})
# Swiggy APIs send 200 for error responses, so cannot do a status check.
Expand All @@ -144,8 +148,7 @@ def perform_login():
otp_input = get_input_value(title='Verify OTP',
text='Please enter the OTP sent to your registered mobile number {}'.format(username))

otp_verify_response = session.post(SWIGGY_VERIFY_OTP_URL, headers={'content-type': 'application/json',
'User-Agent': 'Mozilla/Gecko/Firefox/65.0'},
otp_verify_response = session.post(SWIGGY_VERIFY_OTP_URL, headers={'content-type': 'application/json'},
json={"otp": otp_input, '_csrf': csrf_token})

if otp_verify_response.text == "Invalid Request":
Expand Down

0 comments on commit 7d4a596

Please sign in to comment.