mahendrakalkura / www.bet365.com

44 stars 16 forks source link

TypeError: sequence item 0: expected str instance, int found #4

Closed ghost closed 5 years ago

ghost commented 6 years ago

opening connection... Traceback (most recent call last): File "manage.py", line 124, in web_sockets.connect() File "manage.py", line 62, in connect super(WebSockets, self).connect() File "C:\Users\youri\AppData\Local\Programs\Python\Python36\lib\site-packages\ws4py\client__init.py", line 238, in connect self.protocols, self.extensions = self.process_handshake_header(headers) File "C:\Users\youri\AppData\Local\Programs\Python\Python36\lib\site-packages\ws4py\client\init__.py", line 334, in process_handshake_header extensions = ','.join(value) TypeError: sequence item 0: expected str instance, int found

caiyundong commented 5 years ago

Try python 2.7, no problem.

Problem happens for Python 3, need to change the ws4py file:
elif header == b'sec-websocket-protocol': print(value) value = value.decode("utf-8") protocols = ','.join(value)

        elif header == b'sec-websocket-extensions':
            print(value)
            value = value.decode("utf-8")
            extensions = ','.join(value)
mahendrakalkura commented 5 years ago

@caiyundong Can you please send a pull request?

caiyundong commented 5 years ago

hi, Mahendra

Thank you so much for your code.

For the following topics

'HL_L1_Z3_C1_W4', 'HR_L1_Z3_C1_W4', 'InPlay_1_3', 'LHInPlay_1_3', 'Media_l1_Z3', 'OVInPlay_1_3', 'XI_1_3', 'XL_L1_Z3_C1_W4', It fails to fetch the messages, here is the console message:

opening connection... b'permessage-deflate; server_no_context_takeover; client_max_window_bits=15' b'zap-protocol-v1' opened connection fetching session id... session id: 79F65F2244C7955DA1FD81CBF3CAEC90000003 sending message: '#\x03P\x01__time,S_79F65F2244C7955DA1FD81CBF3CAEC90000003\x00' received message: 100M07-WtPkZ3qvkwuQ sending message: '\x16\x00OVInPlay_1_3\x01' received message: timeF|IN;TI=20180927091639492;UF=55;| ['time', 'F|IN;TI=20180927091639492;UF=55;|'] closed connection code: 1006 reason: Going away

Do you have any detailed documentation? Thank you so much.

best regards, yundong

On 27 Sep 2018, at 4:14 PM, Mahendra Kalkura notifications@github.com wrote:

@caiyundong https://github.com/caiyundong Can you please send a pull request?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mahendrakalkura/www.bet365.com/issues/4#issuecomment-425000159, or mute the thread https://github.com/notifications/unsubscribe-auth/ABx4VOId7WYeEwyHOdFPOsFiFgjHfMmkks5ufIjjgaJpZM4UO3Sv.

mahendrakalkura commented 5 years ago

For the following topics

I wrote this a couple of years ago. I am sure the topics have changed since then. Can you grab the topics from a live web browser session? I am told that they differ based on your geographic location.

Do you have any detailed documentation?

Unfortunately, no. I built this as a quick prototype trying to mimic what the JS version of their code did.

caiyundong commented 5 years ago

'HL_L10_Z0_C1_W3', 'HM_L10_Z0_C1_W3', 'HR_L10_Z0_C1_W3' 'OVInPlay_10_0'

I have changed to latest one, but seems not working.

Now wss url is wss://premws-pt3.365lpodds.com/zap/?uid=3461213776559502

I am not sure whether there is a need to provide uid, not sure how it is generated.

mahendrakalkura commented 5 years ago

I am not sure either. I will check it over the weekend and report back to you.

caiyundong commented 5 years ago

hi mahendrakalkura

I am able to get the content with javascript code for "OVInPlay_10_0" etc. However, with this code, I failed to get the session id, still thinking to solve it. Now I can to open the website, and manually copy the session_id into my code.

For current python code not working, it might be either 1) coding problem (but for CONFIG_10_0, it has no problem); or 2) session_id problem;

My skype id is caiyundong. You can add me at your convenient time then we can have a discussion.

best regards, yundong

const WebSocket = require('ws');
const request = require('request');
const https = require('https');

const ws = new WebSocket("wss://premws-pt3.365lpodds.com/zap/?uid=17434651488051012", "zap-protocol-v1", {
        perMessageDeflate: true,
        clientMaxWindowBits: true,
        protocolVersion: 13
    }
);

ws.on('open', function open() {
    console.log("socket opened")

    /*
    request('https://www.bet365.com/#/IP/', function (error, response, body) {
                                              console.log('error:', error); // Print the error if one occurred
                                              console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
                                              console.log('body:', body); // Print the HTML for the Google homepage.
    });

    https.get('https://www.bet365.com/#/IP/', (res) => {
      console.log('statusCode:', res.statusCode);
      console.log('headers:', res.headers);

      res.on('data', (d) => {
        process.stdout.write(d);
      });

    }).on('error', (e) => {
    console.log('here')
      console.error(e);
    });*/

    session_id = '8D15C906B2604956A81179FB487AA430000003'
    ws.send(String.fromCharCode(35) + String.fromCharCode(3) + String.fromCharCode(80) + String.fromCharCode(1) + "__time,S_"+ session_id + String.fromCharCode(0));
  });

function parseEvent(event_arr) {
    var arr = {};
    event_arr.forEach(function(element){
        var element_arr = element.split("=");
        if(element_arr.length>1) {
            arr[element_arr[0]] = element_arr[1];
         }
    });
    return arr;
}

var event_list = [];
var fixture_list = [];

ws.on('message', function incoming(data) {
  //console.log("Received: "+data);
  if(data.charAt(0)=='1'){
    console.log("Start now")
    //CONFIG_10_0,OVInPlay_10_0,Media_L10_Z0,XL_L10_Z0_C1_W3
    ws.send(String.fromCharCode(22)+String.fromCharCode(0)+"CONFIG_10_0,OVInPlay_10_0,Media_L10_Z0,XL_L10_Z0_C1_W3,OVM1"+String.fromCharCode(1))
  }
  else if(data.startsWith(String.fromCharCode(20)+"OVInPlay")) {
       //split data
       //console.log("Received: "+data);

       ws.send(String.fromCharCode(22)+String.fromCharCode(0)+"OVM1"+String.fromCharCode(1))
       var data_arr = data.split("|");
       data_arr.forEach(function(element) {
              //console.log(element);
              var d_arr = element.split(";")
              var event = parseEvent(d_arr);
              //console.log(d_arr[0])
              if(d_arr[0]=='EV') {
                //filter all football matches
                if(element.includes('C1A')){
                    console.log("======Football events======")
                    console.log(JSON.stringify(event))

                    event_list.push(event['C3'])
                    console.log(event_list)
                }
              }
              else if(d_arr[0]=='MA') {
                //console.log(element)
                if(event_list.indexOf(event['FI'])>=0){
                    console.log(element)
                }
              }
              else if(d_arr[0]=='PA') {
                //PAList
                if(event_list.indexOf(event['FI'])>=0){
                    console.log(element)
                    fixture_list.push(event['IT'])
                    console.log(fixture_list)
                }
              }
              else if(d_arr[0].startsWith('OV')) {
                //odds update
                console.log(d_arr[0])
              }
       })
  }
  else {
    //split for all the updates
    var data_arr = data.split(String.fromCharCode(8));

    data_arr.forEach(function(element){
        //console.log(element)
        var d_arr = element.split(String.fromCharCode(1)+"U|");
        if(d_arr.length>1){
            //console.log(d_arr)
            // fetch the fixture id, e.g. OV76511935C18A_10_0
            fi = d_arr[0].replace(/[^a-zA-Z0-9_]/g, "")
            // fetch the update info: TU=20181003033018;TS=47;TT=0;|'
            update = d_arr[1].split(";")
            var event = parseEvent(update);

            if(fixture_list.indexOf(fi)>=0){
                console.log(fi)
                console.log(event)
            }
            else {

            }
        }
    });
  }
});

ws.on('error', function error(data) {
    console.log(data);
});
mahendrakalkura commented 5 years ago

The following seem to work.

_URLS_SESSION_ID = 'https://www.bet365.com.cy/en/?#/AS/B1/'
_TOPICS = [
    '__host',
    'CONFIG_1_3',
    'LHInPlay_1_3',
    'Media_l1_Z3',
    'XI_1_3',
]
davidvardany commented 5 years ago

Hi mahendrakalkura,

I'm trying your code and after 1006 codes now I have successful connection to server, I'm using latest TOPICS provided by you and always getting following message. received message: timeU|IN;TI=20181021235542593;UF=55;| ['time', 'U|IN;TI=20181021235542593;UF=55;|']

I want to get live and prematch odds. I think I should send some match id's to server to get their data, but how I should do this? Can you please help me? My skype : davo6663 I'm getting 1006 using topics from chrome. screenshot from 2018-10-22 03-02-11

Best Regards, David

p9s commented 5 years ago

You also need to sent matchid to the websocket. I suggest you use mobile.bet365.com to replace www.bet365.com

PS: maybe bet365 that has new tech to replace websocket, the url likes:
https://premlp-pt3.365lpodds.com/pow2/