strange problems with urllib2

2005-10-26 Thread jdonnell
When I run this code on windows it runs quickly (about a second per
image) but when I run it on linux it runs very very slowly (10+ seconds
per image). Is this a bug or am I missing something? On windows I tried
2.4.2 and 2.4.1 on linux i'm running 2.4.1

print 'starting'
f =
urllib2.urlopen('http://site.heavenlytreasures.com/images/e6115.jpg')
outfile = open('e6115.jpg', 'wb')
outfile.write(f.read())
outfile.close()
f.close()
print 'finished'

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange problems with urllib2

2005-10-27 Thread jdonnell
I haven't checked them, but will do it now. However, I don't have
problems with anything but python. I can download that image in less
than a second with wget or in my browser. I know that I had ipv6
problems before. I had to turn it off because of my nat router so I'll
look into that sort of thing.

-- 
http://mail.python.org/mailman/listinfo/python-list


can't start new thread

2005-07-08 Thread jdonnell
I'm at a loss on this one. I have a multithreaded script that gets
'thread.error: can't start new thread' errors seemingly randomly. I
just got it right after starting the script when it was trying to
create the 5th thread. Usually the script will run for a while before
throwing this error, but sometimes it throws it right away.

This script has worked without a problem for months, but I did make
some changes to it recently. I don't see how those changes would cause
this error though. It's also on a VPS so it's possible that they
changed something in the OS. Does anyone have any suggestions about
possible causes of this error?

I'm using Python 2.2.3 on a custom vps version of FC1.

-- 
http://mail.python.org/mailman/listinfo/python-list


can't start new thread

2005-08-31 Thread jdonnell
I posted this about a month ago and peter asked for a stack trace. I
didn't get the error again until yesterday and here is the stack trace
and what I posted before.

Traceback (most recent call last):
  File "./ab.py", line 240, in ?
main()
  File "./ab.py", line 217, in main
abThread.start()
  File "/usr/lib/python2.2/threading.py", line 396, in
start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread


I'm at a loss on this one. I have a multithreaded script that gets
'thread.error: can't start new thread' errors randomly. I
just got it right after starting the script when it was trying to
create the 5th thread. Usually the script will run for a while before
throwing this error, but sometimes it throws it right away.

This script has worked without a problem for months, but I did make
some changes recently. I don't see how those changes would cause
this error though. It's also on a VPS so it's possible that they
changed something in the OS. Does anyone have any suggestions about
possible causes of this error?

I'm using Python 2.2.3 on a custom vps version of FC1.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't start new thread

2005-08-31 Thread jdonnell
>Maybe some other VPS(s) under the host OS have spun enough processes
>or threads to make the host OS exhaust some limit.

I'm not familiar with any hard limits in linux. Is there a config file
with these settings?

-- 
http://mail.python.org/mailman/listinfo/python-list


is there a better way to check an array?

2005-09-01 Thread jdonnell
I want to check if a value is in an array. I'm currently doing it as
follows, but I just don't like this way of doing it. It seems
unpythonic.

fieldIsRequired = true
try:
notRequiredAry.index(k)
fieldIsRequired = false
except ValueError:
pass

# throw expception if field is required and is empty
if(product[k] == '' and fieldIsRequired):
raise GMError(k + ' is required')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way to check an array?

2005-09-01 Thread jdonnell
Thanks for all the help everyone.

Steve, sets are perfect. I didn't even realize they existed. Somehow I
completely missed that part of the tutorial. Thanks :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP Embedded In Python

2005-02-07 Thread jdonnell
I'm not sure exactly what your trying to do, but I use php and python
together a lot. I usually call the python script from php with the
passthru function like this:



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP Embedded In Python

2005-02-08 Thread jdonnell
Well it depends on how php is installed. Is it a linux system? Do you
know how to run a php script from the command line?

Once you have the php script running from the command line then you
need to use the os module in python. There are a couple different ways
to do it. Read the following for more info.
http://docs.python.org/lib/os-process.html
http://docs.python.org/lib/os-newstreams.html#os-newstreams

simple example:

import os
handle = os.popen('path/to/yourScript.php', 'r')
print handle.read()

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP Embedded In Python

2005-02-09 Thread jdonnell
Ok, I'm still a little confused. You mention header.html and
access.php.

For access.php use the os call. You'll probably want to use popen, and
you also need to change your php script slightly. In order to run php
scripts from the command line you have to put
#!/usr/bin/php
as the first line in the php script. You then need to make sure that
it's executable. Run this from the command line:
chmod 755 access.php
Now you can call it from python with os.popen('/path/to/access.php')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Second posting - Howto connect to MsSQL

2005-02-13 Thread jdonnell
" Since this is (sort of) my second request it must not be an easy
solution.
Are there others using Python to connect MsSQL? "

http://sourceforge.net/projects/mysql-python

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting milliseconds in Python

2005-02-16 Thread jdonnell
"This is no good, I am looking for milliseconds, not seconds.. as
stated
above. "

The docs are not very clear. I had the same issue when I was trying to
do the same thing, but the time and datetime modules return
milliseconds on my linux machines.

-- 
http://mail.python.org/mailman/listinfo/python-list


web spider and password protected pages

2005-02-16 Thread jdonnell
I've been writing a simple web spider for fun, and I've run into a
problem I can't figure out. The spider hangs (waits for username and
pass) when I hit a page that requires .htaccess authentication.

self.f = urllib.urlopen('http://blogbloc.com/~jay/test/')
#nothing below here gets executed
print self.f.info()
...

It hangs as soon as I call urllib.urlopen(). I was going to try to read
the info and break for pages that require authentication, but it hangs
before I can call self.f.info()

Any ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web spider and password protected pages

2005-02-16 Thread jdonnell
"I quickly found
a page that starts "Here is an explanation about how to handle password
protected sites."

...

I hope that teaches you a bit about how to fish, rather than
just giving you one. ;-) "

Actually, I found a much easier solution, but since you know how to
fish I don't need to tell you what it is ;)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web spider and password protected pages

2005-02-16 Thread jdonnell
"Nevertheless, perhaps you'll still post the answer here so
that others who come along later can benefit from your
experience in the same way that you benefited from reading
whatever page you found (even if you didn't benefit from
my suggestions...). "

Your funny :) Perhaps you should take your own advice. My guess is that
the google search you described will return different results in a few
months. Your first post won't benefit those who "come along later".

"The spider hangs (waits for username and
pass) when I hit a page that requires .htaccess authentication."

I was using urllib.
urllib2 doesn't have this problem. Simply switching urllib to urllib2
fixed the problem

-- 
http://mail.python.org/mailman/listinfo/python-list


problems with  character

2005-03-22 Thread jdonnell
I have a mysql database with characters like      » in it. I'm
trying to write a python script to remove these, but I'm having a
really hard time.

These strings are coming out as type 'str' not 'unicode' so I tried to
just

record[4].replace('Â', '')

but this does nothing. However the following code works

#!/usr/bin/python

s = 'a  aaa'
print type(s)
print s
print s.find('Â')

This returns

a  aaa
6

The other odd thing is that the  character shows up as two spaces if
I print it to the terminal from mysql, but it shows up as  when I
print from the simple script above. 
What am I doing wrong?

--
http://mail.python.org/mailman/listinfo/python-list


Re: problems with  character

2005-03-23 Thread jdonnell
Thanks for all the replies. I just got in to work so I haven't tried
any of them yet. I see that I wasn't as clear as I should have been so
I'll clarify a little. I'm grabbing some data from msn's rss feed.
Here's an example.
http://search.msn.com/results.aspx?q=domain+name&format=rss&FORM=ZZRE

The string ' all domain name extensions » Good' is where I have a
problem. The
'»' shows up as  '    »' when I write it to a file or stick
it in mysql. I did a hex dump and this is what I see.

[EMAIL PROTECTED]:~/scripts> cat test.txt
extensions » Good
[EMAIL PROTECTED]:~/scripts> xxd test.txt
000: 6578 7465 6e73 696f 6e73 20c2 a020 c2a0  extensions .. ..
010: 20c2 bb20 476f 6f64 0a.. Good

One thing that jumps out is that two of the Â's are c2a0, but one of
them is c2bb. Well, those are the details since I wasn't clear before.

--
http://mail.python.org/mailman/listinfo/python-list


Re: problems with  character

2005-03-23 Thread jdonnell
Thanks everyone, I got it working earlier this morning using deelan's
suggestion. I modified the code in his link so that it removes rather
than replaces the characters.

Also, this was my first experience with unicode and what confused me is
that I was thinking of a unicode object as an encoding, but it's not.
It's just a series of bytes and you later tell it to use a specific
encoding like utf-8 or latin-1. Thanks again for all the help.

-- 
http://mail.python.org/mailman/listinfo/python-list


adodb, sql server, and last insert id

2005-05-02 Thread jdonnell
I'm not very familiar with sql server or adodb. I'm writing a python
script that uses adodb as described at http://www.ecp.cc/pyado.html,
but I can't figure out how to get the id of my last insert.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adodb, sql server, and last insert id

2005-05-04 Thread jdonnell
Thanks for the reply. I found that before I posted, but that doesn't
look thread safe and I haven't found anything that says it is or isn't.

-- 
http://mail.python.org/mailman/listinfo/python-list