0

I'm unable to connect to the Android Scripting layer server. When I run the command I get the following error:

> >>> a = android.Android() Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "android.py", line 34, in
> __init__
>     self.conn = socket.create_connection(addr)   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
> line 553, in create_connection
>     for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 8] nodename nor servname provided, or not
> known

Steps that I've taken: 1. setup adb forwarding. 2. Made available the Android.py file to the interpreter. 3. Started a private server and connected the device to the computer.

What could be wrong?

fixxxer
  • 15,568
  • 15
  • 58
  • 76

2 Answers2

3

Did you export the "AP_PORT" environment variable?

It should be set to the port forwarded to.

For example, if you set the forwarding port like this:

$ adb forward tcp:9999 tcp:{SL4A port}

You need to set the AP_PORT before entering the python interpreter, like this:

$ export AP_PORT=9999

I have a script that sets the environment up and starts the python interpreter here:

https://github.com/georgegoh/Android-Scripting/blob/master/py4a_start.sh

I've only tested and used it on Ubuntu, so YMMV.

George Goh
  • 46
  • 1
  • I had forgotten to do 'export AP_PORT=9999' thinking that adding it to the .bash_profile and starting on a new shell would do the rest. And, your script works fine on Mac OS 10.6.8 too. :) – fixxxer Nov 07 '11 at 05:15
  • I have tried your script on Kubuntu 13.04, but I cannot `import android`, why? Thanks. – qed Aug 03 '13 at 12:39
0

Environment: Eclipse with the pydev plugin and Android developement in Linux.

If the same problem arises even after doing George Goh's solution, then pass the environment variable with the value as AP_PORT=9999 using the interpreter setting of Eclipse.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Steve Harrison
  • 315
  • 3
  • 8