Closed trbedwards closed 6 years ago
Can I suggest you to try to implement a simple example using just python's httplib, and not using requests? Maybe there are some android permissions that are blocking your http requests..
I've constructed an example which uses http.client
(the python3 version of httplib
).
In bootstrap.py:
from http.client import HTTPConnection
def router(args):
# same as usual
def http_request(args):
conn = HTTPConnection("www.google.com")
print("sending request")
conn.request("GET", "/")
print("getting response")
r1 = conn.getresponse()
print(r1.status, r1.reason)
return str(r1.status)
routes = {
'http_request' : http_request
}
and in MainActivity.java we call json.put("function", "http_request")
.
I get the same errors as before. If I don't copy _socket.so
and the other .so files into the python directory I get ImportError: no module named '_socket'
. If I do copy all the .so files, then I get a SIGSEGV error which I've tracked down to a call of the _socket.getaddrinfo
function.
Ah, you were right about the android permissions! I added the following line to my AndroidManifests.xml file:
Now everything works :)
How do I then tell pybridge to use the correct architecture specific _socket.so
file? At the moment I'm manually copying _socket.so
from the arm64-v8a
libs in the crystax ndk, but I guess there's a more elegant automated way to do this?
Glad it worked for you.. 👍 I don't have any solution to automatically copy python files by architecture as I want to keep pybridge simple to understand and "hack"..
Not sure if this is the right place to post the issue, as it may be more related to the crystax ndk, but I thought I'd give it a shot and see if there is a solution or workaround!
I'm attempting to use pybridge to make HTTP post requests from python code. At first I installed the
requests
library into the assets/python folder, but then it was raising an ImportError as it was missing the C extension called_socket
. So I copied over_socket.so
fromcrystax-ndk/sources/python/3.5/libs/arm64-v8a/modules
but then I get a seg fault when callingrequests.post
:I've tracked down the error to a call made to
_socket.getaddrinfo
. I've tried recompiling_socket.so
using socketmodule.c from the Python source code and the crystax ndk, but I still get the same error. I've also tried botharmeabi-v7a
andarm64-v8a
architectures.Any thoughts into how I could solve this problem? Is there a workaround that allows me to make http requests within the python code?
Thanks for your time