O'Reilly Forums: Chapter 8 - Debugging When Things Go Wrong - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 8 - Debugging When Things Go Wrong

#1 User is offline   agaskell 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 26-December 10

Posted 26 December 2010 - 10:16 PM

I'm on page 277 where we run coachapp.py and it's not working. No error message in the terminal, just "Process has exited. Close terminal?". Requests aren't coming through to the web server (the web server is running though).

I'm using Android 2.3 and SL4A r3. I'm also running code downloaded from the book's page. What are some steps I can take to see exactly where it's failing?
0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 27 December 2010 - 05:34 AM

Rather than clicking on the run wheel to execute your program on the emulator, click on the little terminal icon to the left of the run wheel. This *also* runs your program, but shows you any error messages generated by your script (assuming there are any).

The other thing you could do is add some print statements to your code and see if they appear in the terminal window as your program executes. Also, be sure to check your code carefully for typos.

One other thing: make sure your code (either yours or the downloaded code) is using the correct IP address for your server.

Good luck.

Paul.
0

#3 User is offline   agaskell 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 26-December 10

Posted 27 December 2010 - 06:58 PM

Found out the issue. I don't know if this is a typo or because I'm using newer versions than the book, but it worked after I changed "from urllib2 import urlopen" to "from urllib import urlopen".
0

#4 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 28 December 2010 - 04:29 AM

QUOTE (agaskell @ Dec 27 2010, 06:58 PM) <{POST_SNAPBACK}>
Found out the issue. I don't know if this is a typo or because I'm using newer versions than the book, but it worked after I changed "from urllib2 import urlopen" to "from urllib import urlopen".


Ummm... interesting. I'll check this out. Thanks.

--Paul.
0

#5 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 28 December 2010 - 08:20 AM

Hi folks.

I've checked this out and the behaviour of the code differs based on the version of Android you target. Here's the content of an email I've just sent to the SL4A mailing list to try and get some resolution on this issue.

>>>>>>>>>
Hi folks.

On a 2.2 AVD running SL4A_r3 with Python, I can "import urllib2" and use its facilities with no issues.

On a 2.3 AVD running SL4A_r3 with Python, when I "import urllib2" the Python emulator immediately terminates.

Not sure if this is an Android issue, an SL4A issue or a Python one, but I thought I'd start here to try and see if anyone can shed any light on this weirdness.
<<<<<<<<<

I'll keep this forum up-to-date with any and all developments.

--Paul.
0

#6 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 28 December 2010 - 03:14 PM

Status update: this appears to be a problem with the current SL4A Python build (which needs to be recompiled for 2.3, Gingerbread). We are going to have a go at fixing this. The code in the book is OK - it's a Python problem on Android (for now).

--Paul.
0

#7 User is offline   Nasos Thomos 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 28-December 10

Posted 01 January 2011 - 03:36 PM

Hello folks,

I'm using Android 2.3 and SL4A r3 too (Ubuntu 10.10 via VirtualBox). Indeed the urllib2 is an issue. Also as an addition, I have set-up the web server that the emulator tries to fetch the data to address 10.0.2.2. Refer to the "Network Address Space" section in the link below:

http://developer.android.com/guide/develop...s/emulator.html

At least it worked for me.

Thanks,

Thanasis
0

#8 User is offline   AntonyL 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 03-July 11

Posted 10 July 2011 - 02:53 AM

I just came across this. Looking at the terminal window (instead of clicking on the run wheel), the error given is:

urlopen error [Errno 111] Connection refused

And watching the log in the simple_httpd terminal window, there is no GET request which is what would be expected (and is what happens when running generate_names.py from a web browser)

Changing from
from urllib2 import urlopen
to
from urllib2 import urlopen
didn't seem to make any difference.

I'm using Android 2.2, API version 8 and using SL4A r1.

Little bit stuck now - I can run the generate_names.py from a web browser:
http://127.0.0.1:808...nerate_names.py

but the emulator doesn't like it:
web_server    = 'http://127.0.0.1:8080'
get_names_cgi = '/cgi-bin/generate_names.py'


Please advise if anyone has solved this!

Thanks

Antony
0

#9 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 10 July 2011 - 08:46 AM

This is a common mistake that programmers new to Android make. You are asking your Python program on your Android emulator to connect to 127.0.0.1, which is the address for the localhost device... which is the Android emulator (which isn't running the server, as your computer is). When you tested things on your computer, you used 127.0.0.1, but when you test from the Android emulator, you need to use the actual IP address of the computer running the server (even though the emulator is "running" on the self same computer).

On Mac/Linux, use "ifconfig" to work out the correct IP address to use. On Windows use "ipconfig" or "winipcfg" to do the same thing. Note how, on page 276, I use "192.168.1.33" as my server address, as that's the IP address my home router allocated to my laptop during testing. Your home IP address might be something similar.

Hope this helps. :-)

--Paul.
0

#10 User is offline   AntonyL 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 03-July 11

Posted 10 July 2011 - 04:23 PM

So 127.0.0.1 means "myself" which to the emulator would mean itself rather than the laptop outside of the emulator.

ifconfig (on Mac) showed me the correct IP address to use.

This works now as per the book (urllib2 works for Android 2.2, API version 8, SL4A version r1)

Paul, thank you very much for your support. Especially on a Sunday!

Regards

Antony
0

#11 User is offline   AndrewGLK 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 29-March 12

Posted 29 March 2012 - 01:35 AM

Hi,
I encountered the same issue of not getting any reply till I did the following:

1) Use ipconfig to find the IPv4 Address and changed the IP in "web_server = 'http://xx.xx.xx.xx:8080' " accordingly.

2) Change the coachapp.py import statement:
"from urllib2 import urlopen" -> "from urllib import urlopen"
=> Use urllib instead of urllib2.

3) In addition, sometimes, if "pushing" the script cannot work, I found restart the AVD helps.

4) Tips: I also found installing the latest Android SDK -> Extras -> Intel Hardware Accelerated Execution Manager, will help to speed up the AVD loading.

Tested with:
1) Windows7 PC
2) Python3.2 on PC
3) sl4a_r4.apk on AVD (Android device)
4) PythonForAndroid_r4.apk on AVD (Android device)
5) AVD = Android 2.3.3 (API10)

Regards

This post has been edited by AndrewGLK: 29 March 2012 - 01:48 AM

0

#12 User is offline   Bobtista 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 09-December 13

Posted 09 December 2013 - 02:21 PM

You just saved my sanity for the day. I was getting no errors, just "app.py has exited." The book doesn't explain HOW to run a python terminal on the virtual device. I tried running the terminal in "Dev tools" but kept getting "Permission Denied" when I tried running sl4a or python. Lots of resources on the web said I should root the virtual device - which sounded like a lot of work for a silly problem. Even the terminal from within sl4a was giving me permission denied when I tried to run python something.py. That little effing button was right in front of me in the sl4a gui the whole time. Two hours of pulling my hair out - thank you Paul, you are my savior for the day.

Cheers,

Bobby

View Postpaulbarry, on 27 December 2010 - 05:34 AM, said:

Rather than clicking on the run wheel to execute your program on the emulator, click on the little terminal icon to the left of the run wheel. This *also* runs your program, but shows you any error messages generated by your script (assuming there are any).

The other thing you could do is add some print statements to your code and see if they appear in the terminal window as your program executes. Also, be sure to check your code carefully for typos.

One other thing: make sure your code (either yours or the downloaded code) is using the correct IP address for your server.

Good luck.

Paul.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users