0

I'm making a script to open ports on my router / modem via getting the open port POST request and using it here but I get this error when sending: TypeError: a bytes-like object is required, not 'str'. It should just send the POST request and open the port not the error.

    url = "http://192.168.0.1/apply_abstract.cgi" # http://192.168.0.1/wan_portforwarding.htm?m=adv
    reqInfo = {
        'action: ui_firewall',
        'httoken: REMOVED FOR SAFETY',
        'submit_button: wan_portforwarding.htm',
        '786434001000: ' + GlobalForwardingName,
        '786433001000: 1',
        '786435001000: ' + GlobalInternalIP,
        '#786437001000: ' + GlobalProtocol,
        '786438001000: ', GlobalLanPort,
        '786439001000: ', GlobalLanPort,
        '786440001000: ', GlobalWanPort,
        '786441001000: ', GlobalWanPort
    }

    sendReq = requests.post(url, data = reqInfo)```
iUseYahoo
  • 3
  • 4
  • Does this answer your question? [TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3](https://stackoverflow.com/questions/33054527/typeerror-a-bytes-like-object-is-required-not-str-when-writing-to-a-file-in) – Dennis Kozevnikoff Sep 07 '21 at 18:45
  • Im not trying to write to a file though.. – iUseYahoo Sep 07 '21 at 18:46

1 Answers1

1

your are not sending a dict object, only strings this could be the main problem just try this:

reqInfo = {
    'action': ui_firewall,
    'httoken': 'REMOVED FOR SAFETY',
    'submit_button': wan_portforwarding,
    '786434001000':   GlobalForwardingName,
    '786433001000': 1,
    '786435001000':  GlobalInternalIP,
    '#786437001000': GlobalProtocol,
    '786438001000':  GlobalLanPort,
    '786439001000':  GlobalLanPort,
    '786440001000':  GlobalWanPort,
    '786441001000':  GlobalWanPort
}

sendReq = requests.post(url, data = reqInfo)

check the documentation of request: https://docs.python-requests.org/en/master/user/quickstart/

DavidsDvm
  • 54
  • 3