0

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
rafaelSorel
  • 41
  • 1
  • 6
  • Show us how you used the cookie jar so we can help you. Otherwise look at the canonical answer. – Robert Moskal Jan 08 '16 at 23:44
  • 1
    Possible duplicate of [How to send cookies in a post request with the Python Requests library?](http://stackoverflow.com/questions/7164679/how-to-send-cookies-in-a-post-request-with-the-python-requests-library) – Robert Moskal Jan 08 '16 at 23:44
  • Added cookieJar use in main post – rafaelSorel Jan 08 '16 at 23:57
  • I used the same code as in here but no success : [link]http://stackoverflow.com/questions/7164679/how-to-send-cookies-in-a-post-request-with-the-python-requests-library[link] – rafaelSorel Jan 09 '16 at 00:02
  • what you are doing doesn't seem to make any sense. I don't see you logging in, saving the cookie to the jar, and then making the search request. – Robert Moskal Jan 09 '16 at 01:00
  • The first post command make me logged in. then I got cookies and store them. – rafaelSorel Jan 09 '16 at 11:18
  • when I set cookies that is comming from browser it worked: cookie = {'JSESSIONID': '0D2E03FG5530D6E9F508194A9CDE5AD', 'X-BE' : 'N1'} r2 = requests.get('https://shahid.mbc.net/arContent/getPlayerContent-param-.id-127917.type-player.pricingPlanId-8879.html',cookies=cookie) – rafaelSorel Jan 09 '16 at 11:45
  • @rafaelSorel did you find a solution to login via python ? – user1788736 Nov 20 '16 at 05:45
  • YEs indeed, the think is there is a twice post you need to perform in order to get logged in, I had to track the login process on a real browser to see what is going on and got logged in. – rafaelSorel Dec 04 '16 at 11:20

0 Answers0