I 'am trying to log into my account and fetch data from a python script to a website but it seems that python never succed while using any browser, it worked very well, here is my code :
import re
import json
import requests
headers = {'Content-Type': 'application/json'}
login_data = {'email': 'test.test@gmail.com', 'password': '0000000000', 'basic':'false'}
s = requests.session()
data = s.post('https://shahid.mbc.net/wd/service/users/login?', json.dumps(login_data), headers=headers).content
r2 = s.get('https://shahid.mbc.net/arContent/getPlayerContent-param-.id-127917.type-player.pricingPlanId-8879.html')
print ( 'r2' + str(r2.content) )
result of this is as follow
r2b'{"data":{"durationSeconds":0,"durationFrames":0,"progressSeconds":0,"progressFrames":0,"advertisements":[],"additionalProperties":{},"drm":false,"planId":0,"error":{"802":"the user has to be subscriber"}},"additionalProperties":{},"error":{}}'
But when I connect using any browser I got the correct data from the last request.
I have tried also using cookiesJar but no success;
Any help please :(
Here is How I used the cookieJar, it is not the first time I used it but this site driving me crazy :
try:
common.addon.log_debug('Need to login since session is invalid')
login_data = {'email': self.get_setting('username'), 'password': self.get_setting('password'), 'basic':'false'}
headers = {'Content-Type': 'application/json'}
url = 'https://shahid.mbc.net/wd/service/users/login?'
common.addon.log_debug('json data: ' + str(json.dumps(login_data)))
source = self.net.http_POST(url, json.dumps(login_data).encode('utf-8'), headers=headers).content
common.addon.log_debug('source: ' + source)
common.addon.log_debug('self.cookie_file: '+str(self.cookie_file))
if re.search('success', source):
print '== cookies Set =='
self.net.save_cookies(self.cookie_file)
self.net.set_cookies(self.cookie_file)
return True
else:
return False