pycurl and curl not working without sudo

2

sorry for my poor English

i have more than two network interfaces and i want send request with specific interface . here is my code in with pycurl:

def curl_post(url, data, iface=None):
    c = pycurl.Curl()
    buffer = BytesIO()
    c.setopt(pycurl.URL, url)
    c.setopt(pycurl.POST, True)
    c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
    c.setopt(pycurl.TIMEOUT, 10)
    c.setopt(pycurl.WRITEFUNCTION, buffer.write)
    c.setopt(pycurl.POSTFIELDS, data)
    if iface:
        c.setopt(pycurl.INTERFACE, iface)
    c.perform()

    # Json response
    resp = buffer.getvalue().decode('UTF-8')

    #  Check response is a JSON if not there was an error
    try:
        resp = json.loads(resp)
    except json.decoder.JSONDecodeError:
        pass

    buffer.close()
    c.close()
    return resp
dat = {"id": 52, "configuration": [{"eno1": {"address": "192.168.1.1"}}]}
res = curl_post("https://emapp.cc/get_my_ip", json.dumps(dat), "enp0s20u1u3")
print(res)

when i run my python code with sudo it works very well. but without sudo it raise timeout error

even in bash :

curl --interface enp0s20u1u3 google.com

not working without sudo.

note: my default interface is enp4s0f2 and when i set this to my code there is no need to sudo

Farzane Karimyan

Posted 2019-12-14T16:26:17.457

Reputation: 21

No answers