Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sending data to server using kivy

I am creating a app using kivy. I have installed simple dhcp server on my android.

import urllib
from kivy.network.urlrequest import UrlRequest

def bug_posted(req, result):
    print('Our bug is posted !')
    print(result)

params = urllib.urlencode({'@number': 12524, '@type': 'issue',
'@action': 'show'})
headers = {'Content-type': 'application/x-www-form-urlencoded',
      'Accept': 'text/plain'}
req = UrlRequest('<ip>:<port>', on_success=bug_posted, req_body=params,
    req_headers=headers)
print req

result = "test"
bug_posted(req, result)

But, when I run this code, it wont logged in my server. how can I log into my server?

like image 478
sam Avatar asked Dec 10 '25 19:12

sam


2 Answers

Did you give the ”INTERNET” permission to your app? Did you check in the logs (a that the service was running? did you try with something else that the thread-based urlrequest (that is useful in gui to avoid blocking, but less in a service)?

(I still don't understand why you mention the dhcp server, your device still access the internet correctly, right?)

like image 126
Tshirtman Avatar answered Dec 12 '25 11:12

Tshirtman


Try calling:

req.wait()

near the end of your code

import urllib
from kivy.network.urlrequest import UrlRequest

def bug_posted(req, result):
    print('Our bug is posted !')
    print(result)

params = urllib.urlencode({'@number': 12524, '@type': 'issue',
'@action': 'show'})
headers = {'Content-type': 'application/x-www-form-urlencoded',
      'Accept': 'text/plain'}
req = UrlRequest('<ip>:<port>', on_success=bug_posted, req_body=params,
    req_headers=headers)
req.wait()

without it the request does not seem to fire for me.

like image 27
Chozabu Avatar answered Dec 12 '25 12:12

Chozabu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!