trigger at TDM/2 only
Hi,
I have a process that I can trigger only at a certain time. Assume I have a TDM
period of 10min, that means, I can only fire my trigger at the 5th minute of
every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with
following algorithm which oly leaves the waiting while loop if minute % TDM/2
is 0 but not if minute % TDM is 0:
min = datetime.datetime.now().timetuple().tm_hour*60 +
datetime.datetime.now().timetuple().tm_min
while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0):
time.sleep(10)
logger.debug("WAIT
"+str(datetime.datetime.now().timetuple().tm_hour*60 +
datetime.datetime.now().timetuple().tm_min))
logger.debug(str(min%(int(tdm_timeslot/2)))+" -
"+str(min%tdm_timeslot))
min = datetime.datetime.now().timetuple().tm_hour*60 +
datetime.datetime.now().timetuple().tm_min
logger.debug("RUN UPDATE CHECK...")
But weird enough, the output I get is something like this:
I would expect my while to exit the loop as soon as the minute turns 1435...
why is it staying in? What am I doing wrong here?
WAIT 1434
3 - 3
WAIT 1434
4 - 4
WAIT 1434
4 - 4
WAIT 1434
4 - 4
WAIT 1434
4 - 4
WAIT 1434
4 - 4
WAIT 1435
4 - 4
WAIT 1435
0 - 5
WAIT 1435
0 - 5
WAIT 1435
0 - 5
WAIT 1435
0 - 5
WAIT 1435
0 - 5
WAIT 1436
0 - 5
RUN UPDATE CHECK...
Thank you for any assistance!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
Re: trigger at TDM/2 only
DaveA, Yep, that seems to just be about it! Much easier! Thanks for the hint! Much appreciated :) Ron On Thursday, June 6, 2013 5:43:11 PM UTC-7, Dave Angel wrote: > On 06/06/2013 08:03 PM, cerr wrote: > > > Hi, > > > > > > I have a process that I can trigger only at a certain time. Assume I have a > > TDM period of 10min, that means, I can only fire my trigger at the 5th > > minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came > > up with following algorithm which oly leaves the waiting while loop if > > minute % TDM/2 is 0 but not if minute % TDM is 0: > > > min = datetime.datetime.now().timetuple().tm_hour*60 + > > datetime.datetime.now().timetuple().tm_min > > > while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0): > > > > You might have spent three minutes and simplified this for us. And in > > the process discovered the problem. > > > > (BTW, min() is a builtin function, so it's not really a good idea to be > > shadowing it.) > > > > You didn't give python version, so my sample is assuming Python 2.7 > > For your code it shouldn't matter. > > > > tdm = 10 > > tdm2 = 5 > > > > y = min(3,4) > > print y > > > > for now in range(10,32): > > print now, now%tdm, now%tdm2, > > print not(now % tdm !=0 ^ now%tdm2 !=0) #bad > > print not((now % tdm !=0) ^ (now%tdm2 !=0)) #good > > > > > > Your problem is one of operator precedence. Notice that ^ has a higher > > precedence than != operator, so you need the parentheses I added in the > > following line. > > > > What I don't understand is why you used this convoluted approach. Why not > > > > print now%tdm != tdm2 > > > > For precedence rules, see: > >http://docs.python.org/2/reference/expressions.html#operator-precedence > > > > > > > > > > -- > > DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: trigger at TDM/2 only
MRAB,
Thanks for the hint! Yep, that's much easier!
Thanks! :)
Ron
On Thursday, June 6, 2013 5:49:55 PM UTC-7, MRAB wrote:
> On 07/06/2013 01:03, cerr wrote:
>
> > Hi,
>
> >
>
> > I have a process that I can trigger only at a certain time. Assume I have a
> > TDM period of 10min, that means, I can only fire my trigger at the 5th
> > minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came
> > up with following algorithm which oly leaves the waiting while loop if
> > minute % TDM/2 is 0 but not if minute % TDM is 0:
>
> > min = datetime.datetime.now().timetuple().tm_hour*60 +
> > datetime.datetime.now().timetuple().tm_min
>
> > while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0):
>
> > time.sleep(10)
>
> > logger.debug("WAIT
> > "+str(datetime.datetime.now().timetuple().tm_hour*60 +
> > datetime.datetime.now().timetuple().tm_min))
>
> > logger.debug(str(min%(int(tdm_timeslot/2)))+" -
> > "+str(min%tdm_timeslot))
>
> > min = datetime.datetime.now().timetuple().tm_hour*60 +
> > datetime.datetime.now().timetuple().tm_min
>
> > logger.debug("RUN UPDATE CHECK...")
>
> >
>
> > But weird enough, the output I get is something like this:
>
> > I would expect my while to exit the loop as soon as the minute turns
> > 1435... why is it staying in? What am I doing wrong here?
>
> >
>
> > WAIT 1434
>
> > 3 - 3
>
> > WAIT 1434
>
> > 4 - 4
>
> > WAIT 1434
>
> > 4 - 4
>
> > WAIT 1434
>
> > 4 - 4
>
> > WAIT 1434
>
> > 4 - 4
>
> > WAIT 1434
>
> > 4 - 4
>
> > WAIT 1435
>
> > 4 - 4
>
> > WAIT 1435
>
> > 0 - 5
>
> > WAIT 1435
>
> > 0 - 5
>
> > WAIT 1435
>
> > 0 - 5
>
> > WAIT 1435
>
> > 0 - 5
>
> > WAIT 1435
>
> > 0 - 5
>
> > WAIT 1436
>
> > 0 - 5
>
> > RUN UPDATE CHECK...
>
> >
>
> Possibly it's due to operator precedence. The bitwise operators &, |
>
> and ^ have a higher precedence than comparisons such as !=.
>
>
>
> A better condition might be:
>
>
>
> min % tdm_timeslot != tdm_timeslot // 2
>
>
>
> or, better yet, work out how long before the next trigger time and then
>
> sleep until then.
--
http://mail.python.org/mailman/listinfo/python-list
dump a multi dimensional dictionary
Hi,
Can I somehow use pickle.dump() to store a dictionary of lists to a file?
I tried this:
>>> import pickle
>>> mylist = []
>>> mydict = {}
>>> mylist = '1','2'
>>> mydict['3'] = mylist
>>> fhg = open ("test", 'w')
>>> pickle.dump(fhg,mydict)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 203, in __init__
self.write = file.write
AttributeError: 'dict' object has no attribute 'write'
>>> print mydict
{'3': ('1', '2')}
or should I just write my own dump function that can hanle thiS?
Please advise!
Thanks,
Ron
--
http://mail.python.org/mailman/listinfo/python-list
binary key in dictionary
Hi,
In my application I have followingf lines:
print curr_mac
print hexlify(buf)
binmac = unhexlify(curr_mac)
tmpgndict[binmac] += buf
curr_mac being a 3Byte MAVC address in ASCII and I want to populate a
dictionary where the value(buf) is indexed by binary mac.
I get this in my code:
Traceback (most recent call last):
File "gateway.py", line 2485, in
main()
File "gateway.py", line 2459, in main
cloud_check()
File "gateway.py", line 770, in cloud_check
gnstr_dict[src] = gn_from_cloud(curr_mac)
File "gateway.py", line 2103, in gn_from_cloud
tmpgndict[binmac] += "HELLO"
KeyError: '\x04\xeeu'
but then again, the following works fine in the python interpreter:
>>> mac = '04ee75'
>>> dat = '2a0001016d03c400040001000a'
>>> mydict = {}
>>> mydict[unhexlify(mac)]=dat
>>> print mydict
{'\x04\xeeu': '2a0001016d03c400040001000a'}
I really seem to do something wrong and can't see what it is. Can anyone help
me further here?
Thank you very much!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
logger doesn't roll over
Hi,
I'm using Python's logger for logging but it doesn't seem to roll over, my file
is now 2.2MB and should've rolled over after ever 1MB.
My code:
logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(
LOGFILE, maxBytes=(1048576*10), backupCount=5
)
What am I doing wrong here, I don't get it.
Thank you!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
trac.util
Hi, I want to install some python driver on my system that requires trac.util (from Image.py) but I can't find that anywhere, any suggestions, anyone? Thank you very much, any help is appreciated! Error: File "/root/weewx/bin/Image.py", line 32, in from trac.util import escape ImportError: No module named trac.util Ron -- http://mail.python.org/mailman/listinfo/python-list
HTTP post with urllib2
Hi,
Why does this code:
#!/usr/bin/python
import urllib2
from binascii import hexlify, unhexlify
host = "localhost"
uri="/test.php"
data ="\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\x64" #Hello World
url="http://{0}{1}?f=test".format(host, uri)
req = urllib2.Request(url, data,{'Content-Type': 'application/octet-stream'})
req.get_method = lambda: 'PUT'
response = urllib2.urlopen(req, 120)
retval = response.read()
print "RETVAL "+retval
return me this:
./post.py
Traceback (most recent call last):
File "./post.py", line 13, in
response = urllib2.urlopen(req, 120)
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 398, in open
req = meth(req)
File "/usr/lib/python2.7/urllib2.py", line 1116, in do_request_
'Content-length', '%d' % len(data))
I don't get it, what's going on here?
Thank you!
--
http://mail.python.org/mailman/listinfo/python-list
Re: HTTP post with urllib2
On Tuesday, August 6, 2013 4:08:34 PM UTC-7, Joel Goldstick wrote:
> On Tue, Aug 6, 2013 at 6:52 PM, cerr wrote:
>
> > Hi,
>
> >
>
> > Why does this code:
>
> >
>
> > #!/usr/bin/python
>
> >
>
> >
>
> > import urllib2
>
> > from binascii import hexlify, unhexlify
>
> >
>
> > host = "localhost"
>
> > uri="/test.php"
>
> > data ="\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\x64" #Hello World
>
> > url="http://{0}{1}?f=test".format(host, uri)
>
> > req = urllib2.Request(url, data,{'Content-Type':
> > 'application/octet-stream'})
>
> > req.get_method = lambda: 'PUT'
>
>
>
> What does the above line do? is it the same as req.get_method = 'PUT'
I guess so, I got this from an example copy & paste :x
>
> > response = urllib2.urlopen(req, 120)
>
>
>
> the docs say req should be a url. Is it?
no, it's an instance of req = urllib2.Request()
>
> > retval = response.read()
>
> > print "RETVAL "+retval
>
> >
>
> >
>
> >
>
> > return me this:
>
> >
>
> > ./post.py
>
> > Traceback (most recent call last):
>
> > File "./post.py", line 13, in
>
> > response = urllib2.urlopen(req, 120)
>
> > File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
>
> > return _opener.open(url, data, timeout)
>
> > File "/usr/lib/python2.7/urllib2.py", line 398, in open
>
> > req = meth(req)
>
> > File "/usr/lib/python2.7/urllib2.py", line 1116, in do_request_
>
> > 'Content-length', '%d' % len(data))
>
> >
>
> >
>
> > I don't get it, what's going on here?
>
> >
>
> > Thank you!
>
> > --
>
> > http://mail.python.org/mailman/listinfo/python-list
>
>
>
> KInda of ducking your questions, but the requests module is a lot
>
> easier to use and
>
> understand:http://docs.python-requests.org/en/latest/
But there must be a way to get this working with urllib alone...
--
http://mail.python.org/mailman/listinfo/python-list
Re: HTTP post with urllib2
On Tuesday, August 6, 2013 5:14:48 PM UTC-7, MRAB wrote:
> On 06/08/2013 23:52, cerr wrote:
>
> > Hi,
>
> >
>
> > Why does this code:
>
> >
>
> > #!/usr/bin/python
>
> >
>
> >
>
> > import urllib2
>
> > from binascii import hexlify, unhexlify
>
> >
>
> > host = "localhost"
>
> > uri="/test.php"
>
> > data ="\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\x64" #Hello World
>
> > url="http://{0}{1}?f=test".format(host, uri)
>
> > req = urllib2.Request(url, data,{'Content-Type':
> > 'application/octet-stream'})
>
> > req.get_method = lambda: 'PUT'
>
> > response = urllib2.urlopen(req, 120)
>
> > retval = response.read()
>
> > print "RETVAL "+retval
>
> >
>
> >
>
> >
>
> > return me this:
>
> >
>
> > ./post.py
>
> > Traceback (most recent call last):
>
> >File "./post.py", line 13, in
>
> > response = urllib2.urlopen(req, 120)
>
> >File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
>
> > return _opener.open(url, data, timeout)
>
> >File "/usr/lib/python2.7/urllib2.py", line 398, in open
>
> > req = meth(req)
>
> >File "/usr/lib/python2.7/urllib2.py", line 1116, in do_request_
>
> > 'Content-length', '%d' % len(data))
>
> >
>
> >
>
> > I don't get it, what's going on here?
>
> >
>
> The docs say """urllib2.urlopen(url[, data][, timeout])""".
>
>
>
> You're calling it as """urllib2.urlopen(req, 120)""".
>
>
>
> In other words, 'url' is req and 'data' is 120.
>
>
>
> It should be """urllib2.urlopen(req, None, 120)""".
Yes, great! That did it! :)
Coming into the office in the morning, sitting down, changing this and get it
working! Good way to start my day! :)
Thanks MRAB!
--
http://mail.python.org/mailman/listinfo/python-list
question about posting data using MultipartPostHandler
Hi,
I want to use http post to upload data to a webserver but I want to pass
multiple arguments within the post i.e.
I know that you can load one item (data)in there like this:
data = {"data":open(filename,"rb")}
response = opener.open(url, data, timeout=TIMEOUT)
but now I want multiple so I tried this:
multipart = ({"data":data}, {"fname":fname}, {"f":f})
response = opener.open(url, multipart, timeout=TIMEOUT)
but I get an error saying "'tuple' object has no attribute 'items'"... how do I
do this correctly?
Thank you!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
http post goes into $_REQUEST instead into $_FILES
Hi,
I have a Python script that is executing an http POST to transfer a file from
the client to the server. I have achieved this with below code:
from binascii import hexlify, unhexlify
from httplib import HTTPConnection, HTTPException
import os
import hashlib
import socket
import urllib2
import time
import subprocess
import MultipartPostHandler
def post_file(filename, data):
try:
wakeup()
socket.setdefaulttimeout(TIMEOUT)
#create multipartpost handler
opener =
urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
#set POST arguments
host = HOST
func = "post_file"
fname = filename
#assemble post URL
url = "http://{0}{1}".format(host, URI)
print "POSTING "+fname
#assemble multipart header
data = {"data":data,"f":func,"fname":filename}
#execute POST
response = opener.open(url, data, timeout=TIMEOUT)
#reads server return value
retval = response.read()
print retval
if "SUCCESS" in retval:
return 0
else:
print "RETVAL: "+retval
return 99
except Exception as e:
print "EXCEPTION time "+str(time.time())+" - "+str(e)
return 99
but my problem is, the data gets posted to the sever but arrives in the
`$_REQUEST` array and I'm expected to post stuff so that it arrives in the
`$_FILES` array (this is a LAMP server). How do I need to modify my code to
deliver it correctly?
Thank you,
--
http://mail.python.org/mailman/listinfo/python-list
replace only full words
Hi, I have a list of sentences and a list of words. Every full word that appears within sentence shall be extended by i.e. "I drink in the house." Would become "I in the ." (and not "I in the .")I have attempted it like this: for sentence in sentences: for noun in nouns: if " "+noun+" " in sentence or " "+noun+"?" in sentence or " "+noun+"!" in sentence or " "+noun+"." in sentence: sentence = sentence.replace(noun, '<' + noun + '>') print(sentence) but what if The word is in the beginning of a sentence and I also don't like the approach using defined word terminations. Also, is there a way to make it faster? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: replace only full words
On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > On 2013-09-28 09:11, cerr wrote: > > > I have a list of sentences and a list of words. Every full word > > > that appears within sentence shall be extended by i.e. "I > > > drink in the house." Would become "I in the ." (and > > > not "I in the .") > > > > This is a good place to reach for regular expressions. It comes with > > a "ensure there is a word-boundary here" token, so you can do > > something like the code at the (way) bottom of this email. I've > > pushed it off the bottom in the event you want to try and use regexps > > on your own first. Or if this is homework, at least make you work a > > *little* :-) > > > > > Also, is there a way to make it faster? > > > > The code below should do the processing in roughly O(n) time as it > > only makes one pass through the data and does O(1) lookups into your > > set of nouns. I included code in the regexp to roughly find > > contractions and hyphenated words. Your original code grows slower > > as your list of nouns grows bigger and also suffers from > > multiple-replacement issues (if you have the noun-list of ["drink", > > "rink"], you'll get results that you don't likely want. > > > > My code hasn't considered case differences, but you should be able to > > normalize both the list of nouns and the word you're testing in the > > "modify()" function so that it would find "Drink" as well as "drink" > > > > Also, note that some words serve both as nouns and other parts of > > speech, e.g. "It's kind of you to house me for the weekend and drink > > tea with me." > > > > -tkc > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > import re > > > > r = re.compile(r""" > > \b# assert a word boundary > > \w+ # 1+ word characters > > (?: # a group > >[-'] # a dash or apostrophe > >\w+ # followed by 1+ word characters > >)?# make the group optional (0 or 1 instances) > > \b# assert a word boundary here > > """, re.VERBOSE) > > > > nouns = set([ > > "drink", > > "house", > > ]) > > > > def modify(matchobj): > > word = matchobj.group(0) > > if word in nouns: > > return "<%s>" % word > > else: > > return word > > > > print r.sub(modify, "I drink in the house") Great, only I don't have the re module on my system :( -- https://mail.python.org/mailman/listinfo/python-list
Re: replace only full words
On Saturday, September 28, 2013 11:07:11 AM UTC-7, MRAB wrote: > On 28/09/2013 18:43, cerr wrote: > > [snip] > > > Great, only I don't have the re module on my system :( > > > > > Really? It's part of Python's standard distribution. Oh no, sorry, mis-nformation, i DO have module re available!!! All good! -- https://mail.python.org/mailman/listinfo/python-list
Re: replace only full words
On Saturday, September 28, 2013 11:17:19 AM UTC-7, Tim Chase wrote: > [mercy, you could have trimmed down that reply] > > > > On 2013-09-28 10:43, cerr wrote: > > > On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > > >> import re > > > > > > Great, only I don't have the re module on my system :( > > > > Um, it's a standard Python library. You sure about that? > > > > http://docs.python.org/2/library/re.html > Oh no, sorry, mis-nformation, i DO have module re available!!! All good! -- https://mail.python.org/mailman/listinfo/python-list
extraction tool using CRF++
Hi, I want to write an extraction tool using CRF++ (http://crfpp.googlecode.com/svn/trunk/doc/index.html). I have written a trainings file and a template: training: banana FOODB-NP bread FOODI-NP template: U01:%x[0,1] U02:%x[1,1] and now I want to go ahead and extract the foods from a sentence like "how do I make a banana bread". Also, I'm unsure how I interface to crf++ with python, I compiled and installed it from source as described on the above website but I don't have a crf module available in python... -- https://mail.python.org/mailman/listinfo/python-list
Re: extraction tool using CRF++
On Tuesday, October 1, 2013 3:04:00 PM UTC, Joost Molenaar wrote: > Hi Ron, > > In the python/ subdirectory of the CRF++ source package there's a > > README with instructions on how to use the CRFPP python module. > Joost, Hoops, didn't see that! Yes, Thanks! :) -- https://mail.python.org/mailman/listinfo/python-list
Broken pipe
Hi There,
I'm very new to Python and i wanna write a script that sends a certain
string to a server. The code I came up with looks like this:
#!/usr/bin/python
import sys
import string
from socket import *
usage="USAGE: "+sys.argv[0]+" ";
if len(sys.argv) != 3:
print usage;
sys.exit(0);
host = sys.argv[1];
port = sys.argv[2];
buf = 1024;
addr = (host,port);
sock = socket(AF_INET, SOCK_STREAM);
data = string.join("NovaxTest",'\n');
sock.send(data);
sock.close();
and I'm calling this script like that: "./TestService.py 127.0.0.1
1514" but when I call it I get following back:
sending data to 127.0.0.1:1514
data: NovaxTest
Traceback (most recent call last):
File "./TestService.py", line 18, in
sock.send(data);
socket.error: [Errno 32] Broken pipe
I understand that UNIX sends an Errno32 if the server closes the
connection. But if i telnet to localhost on 1514 and send NovaxTest by
hand everything works just fine. So what might be wrong here?
Thank you very much!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
Re: Broken pipe
On May 7, 9:45 am, Ron Eggler wrote:
> --
> Ron Eggler
> Suite# 1804
> 1122 Gilford St
> Vancouver, BC V6G 2P5
> Canada
> (778) 230-9442
>
>
>
>
>
> > On Thu, May 6, 2010 at 11:11 PM, Ron Eggler wrote:
> > > On May 6, 2010 10:37:14 pm Chris Rebert wrote:
> > >> On Thu, May 6, 2010 at 10:27 PM, cerr wrote:
> > >> > Hi There,
>
> > >> > I'm very new to Python and i wanna write a script that sends a certain
> > >> > string to a server. The code I came up with looks like this:
> > >> > #!/usr/bin/python
>
> > >> > import sys
> > >> > import string
>
> > >> > from socket import *
> > >> > usage="USAGE: "+sys.argv[0]+" ";
> > >> > if len(sys.argv) != 3:
> > >> > print usage;
> > >> > sys.exit(0);
> > >> > host = sys.argv[1];
> > >> > port = sys.argv[2];
> > >> > buf = 1024;
> > >> > addr = (host,port);
> > >> > sock = socket(AF_INET, SOCK_STREAM);
> > >> > data = string.join("NovaxTest",'\n');
> > >> > sock.send(data);
> > >> > sock.close();
> > >> > and I'm calling this script like that: "./TestService.py 127.0.0.1
> > >> > 1514" but when I call it I get following back:
> > >> > sending data to 127.0.0.1:1514
> > >> > data: NovaxTest
> > >> > Traceback (most recent call last):
> > >> > File "./TestService.py", line 18, in
> > >> > sock.send(data);
> > >> > socket.error: [Errno 32] Broken pipe
> > >> > I understand that UNIX sends an Errno32 if the server closes the
> > >> > connection. But if i telnet to localhost on 1514 and send NovaxTest by
> > >> > hand everything works just fine. So what might be wrong here?
>
> > >> You never called sock.connect(addr). Your code doesn't even use `addr`
> > >> at all.
>
> > > Oh, yeah, hOOps :$
>
> >
>
> > > Hm weird now I get something like:
> > > Traceback (most recent call last):
> > > File "./TestService.py", line 14, in
> > > sock.connect((host,port))
> > > File "", line 1, in connect
> > > TypeError: an integer is required
>
> >
>
> > > What does that mean? :(
>
> > You never converted `port` to an int, it's still a string.
>
> port = int(sys.argv[2])
>
> doesn't seem to help it either :(
>
>
>
> > You might consider reading the socket module docs:
> >http://docs.python.org/library/socket.html
>
> mh, i browsed through it but didn't quite find what i'm looking for, do you
> have any more hints?
>
Ah, okay, I figured that out! I actually just needed to add a \n at
the end to signal the server that this is the end of the line. All
good now, thanks for your help!
--
Ron
--
http://mail.python.org/mailman/listinfo/python-list
huh??? weird problem
Hi There, I got following code: start=time.time() print 'warnTimeout '+str(WarnTimeout) print 'critTimeout '+str(CritTimeout) print 'start',str(start) while wait: passed = time.time()-start print 'passed ',str(passed) if passed >= WarnTimeout: print ' Warning!' ... ... ... which basically means that the loops should go until the warning time has been reached and then i want it to print 'warning!' and execute some warning code. But weirdly enough i get following screen output: warnTimeout 3 critTimeout 5 start 1273882010.43 passed 7.60555267334e-05 passed 0.998471975327 passed 1.99847102165 passed 2.9984691143 passed 3.99847006798 passed 4.998472929 ... ... any one a clue why after 3 seconds it doesn't go into the the if an print 'Warning!'? That's odd... :o Crazy, what am i not seeing? :( -- http://mail.python.org/mailman/listinfo/python-list
DeprecationWarning
Hi There,
I would like to create an scp handle and download a file from a
client. I have following code:
import sys, os, paramiko,time
from attachment import SCPClient
transport = paramiko.Transport((prgIP, 22))
try:
transport.connect(username='root', password=prgPass)
except IOError:
print "Transport connect timed out"
writelog(" Transport connect timed out. \n")
sys.exit()
scp = SCPClient(transport)
writelog("Succesfully created scp transport handle to get P-file
\n")
# Create '/tmp/autokernel' if it does not exist.
if not os.access('./PRGfiles', os.F_OK):
os.mkdir('./PRGfiles')
try:
scp.get("/usr/share/NovaxTSP/P0086_2003.xml","./PRGfiles/
P0086_2003.xml")
writelog("succesfully downloaded P-file \n")
except IOError:
writelog("Downloading P-file failed. \n")
but what i'm getting is this and no file is downloaded...:
/opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning:
BaseException.message has been deprecated as of Python 2.6
chan.send('\x01'+e.message)
09/01/2010 08:53:56 : Downloading P-file failed.
What does that mean and how do i resolve this?
Thank you!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
scp with paramiko
Hi There, I want to download a file from a client using paramiko. I found plenty of ressources using google on how to send a file but none that would describe how to download files from a client. Help would be appreciated! Thanks a lot! Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning
On Sep 1, 5:04 pm, Chris Rebert wrote:
> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote:
> > Hi There,
>
> > I would like to create an scp handle and download a file from a
> > client. I have following code:
>
> > but what i'm getting is this and no file is downloaded...:
> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning:
> > BaseException.message has been deprecated as of Python 2.6
> > chan.send('\x01'+e.message)
> > 09/01/2010 08:53:56 : Downloading P-file failed.
>
> > What does that mean and how do i resolve this?
>
> http://stackoverflow.com/questions/1272138/baseexception-message-depr...
> As the warning message says, line 243 of
> /opt/lampp/cgi-bin/attachment.py is the cause of the warning.
>
> However, that's only a warning (albeit probably about a small part of
> some error-raising code), not an error itself, so it's not the cause
> of the download failure.
> Printing out the IOError encountered would be the first step in
> debugging the download failure.
>
> Cheers,
> Chris
> --http://blog.rebertia.com
Hi Chris,
Thanks for getting back!
I get an "I/O error(2): No such file or directory" error even tho the
file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is
present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is
succesful... :( What am i doing wrong?
Thanks,
Ron
--
http://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning
On Sep 2, 4:25 pm, Chris Rebert wrote:
> On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote:
> > On Sep 1, 5:04 pm, Chris Rebert wrote:
> >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote:
> >> > Hi There,
>
> >> > I would like to create an scp handle and download a file from a
> >> > client. I have following code:
> >>
> >> > but what i'm getting is this and no file is downloaded...:
> >> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning:
> >> > BaseException.message has been deprecated as of Python 2.6
> >> > chan.send('\x01'+e.message)
> >> > 09/01/2010 08:53:56 : Downloading P-file failed.
>
> >> > What does that mean and how do i resolve this?
>
> >>http://stackoverflow.com/questions/1272138/baseexception-message-depr...
> >> As the warning message says, line 243 of
> >> /opt/lampp/cgi-bin/attachment.py is the cause of the warning.
>
> >> However, that's only a warning (albeit probably about a small part of
> >> some error-raising code), not an error itself, so it's not the cause
> >> of the download failure.
> >> Printing out the IOError encountered would be the first step in
> >> debugging the download failure.
>
> >> Cheers,
> >> Chris
>
> > Hi Chris,
>
> > Thanks for getting back!
> > I get an "I/O error(2): No such file or directory" error even tho the
> > file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is
> > present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is
> > succesful... :( What am i doing wrong?
>
> Asking on the Paramiko mailinglist might be more
> fruitful:http://www.lag.net/mailman/listinfo/paramiko
Yep, thanks. I guess I try my luck there then. Thanks!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
listening socket
Hi,
I'm trying to create a listening socket connection on port 1514.
I tried to follow the documentation at:
http://docs.python.org/release/2.5.2/lib/socket-example.html
and came up with following lines:
import socket
host = '' # Symbolic name meaning all available
interfaces
port = 1514 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
but that is not working, i'm getting this:
import: unable to open X server `' @ error/import.c/ImportImageCommand/
362.
./sockettest.py: line 4: host: command not found
./sockettest.py: line 5: port: command not found
./sockettest.py: line 6: syntax error near unexpected token `('
./sockettest.py: line 6: `s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)'
now why would it try to open an x server??? :o
--
http://mail.python.org/mailman/listinfo/python-list
Re: listening socket
On Sep 8, 10:06 am, Benjamin Kaplan wrote:
> On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote:
> > Hi,
>
> > I'm trying to create a listening socket connection on port 1514.
> > I tried to follow the documentation at:
> >http://docs.python.org/release/2.5.2/lib/socket-example.html
> > and came up with following lines:
> > import socket
>
> > host = '' # Symbolic name meaning all available
> > interfaces
> > port = 1514 # Arbitrary non-privileged port
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > s.bind((host, port))
> > s.listen(1)
> > conn, addr = s.accept()
> > print 'Connected by', addr
> > while 1:
> > data = conn.recv(1024)
> > if not data: break
> > conn.send(data)
> > conn.close()
> > but that is not working, i'm getting this:
> > import: unable to open X server `' @ error/import.c/ImportImageCommand/
> > 362.
> > ./sockettest.py: line 4: host: command not found
> > ./sockettest.py: line 5: port: command not found
> > ./sockettest.py: line 6: syntax error near unexpected token `('
> > ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET,
> > socket.SOCK_STREAM)'
>
> > now why would it try to open an x server??? :o
> > --
>
> Because it's not executing it as a Python program. It's trying to
> execute it as a shell script. If you want to run a script as a Python
> program, either call the interpreter directly
> python sockettest.py
>
> or include a Shebang line as the first line of the file that tells the
> computer what interpreter to use
> #!/usr/bin/env python
>
> The file extension itself is meaningless to a Unix shell- it's just a
> part of the file name.
hoops right... heh, thanks... :$ clearly doing too many things at the
same time...
--
http://mail.python.org/mailman/listinfo/python-list
executing script in fork
Hi There, I want to trigger another script and having it running forked to my mother process. I googled around and came up with following: commandlist=['./GPSsim.pl',proto,'files/gps.txt'] subprocess.Popen(commandlist) print "GPS simulator started" This however doesn't seem disconnect stdout but it still throws me back to the shell. How can I launch it with disconnected stdout and still continue running further code in my mother script? Thanks, Ron -- http://mail.python.org/mailman/listinfo/python-list
how to kill a subprocess
Hi There, I'm calling a python script from a php script which again calls a perl script with subprocess.popen(). This seems to work fine so far only that once the python script completed it is becoming a zombie because the perl script in the background is still running... so before i exit the python script, i would need to kill my perl subprocess. How can i do so? Thank you for hints & suggestions! Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: how to kill a subprocess
On Sep 9, 3:29 pm, Alain Ketterlin
wrote:
> cerr writes:
> > I'm calling a python script from a php script which again calls a perl
> > script with subprocess.popen().
> > This seems to work fine so far only that once the python script
> > completed it is becoming a zombie because the perl script in the
> > background is still running... so before i exit the python script, i
> > would need to kill my perl subprocess.
> > How can i do so?
>
> x.terminate() (and then x.wait()) where x is the value returned by
> subprocess.Popen().
Well, this is what I have:
writelog("starting GPS simulator")
commandlist=[GPSsim,proto,GPSfile]
writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
process=subprocess.Popen(commandlist)
writelog("GPS simulator started")
...
...
os.kill(process.pid,9)
os.wait()
but this is not working for me... :( any clues?
> P/S: I'm not sure why the python process survives, and I think your use
> of "zombie" is not correct (afaik a zombie is an exited process whose
> parent hasn't called wait() yet)
This is what I have:
localhost cgi-bin # ps ax | grep py
11853 ?Z 0:00 [python2.6]
12029 pts/1S+ 0:00 grep --colour=auto py
The 'Z' you see there stands for Zombie
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to kill a subprocess
On Sep 9, 4:18 pm, MRAB wrote:
> On 09/09/2010 23:52, cerr wrote:
>
>
>
> > On Sep 9, 3:29 pm, Alain Ketterlin
> > wrote:
> >> cerr writes:
> >>> I'm calling a python script from a php script which again calls a perl
> >>> script with subprocess.popen().
> >>> This seems to work fine so far only that once the python script
> >>> completed it is becoming a zombie because the perl script in the
> >>> background is still running... so before i exit the python script, i
> >>> would need to kill my perl subprocess.
> >>> How can i do so?
>
> >> x.terminate() (and then x.wait()) where x is the value returned by
> >> subprocess.Popen().
> > Well, this is what I have:
>
> > writelog("starting GPS simulator")
> > commandlist=[GPSsim,proto,GPSfile]
> > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
> > process=subprocess.Popen(commandlist)
> > writelog("GPS simulator started")
> > ...
> > ...
> > os.kill(process.pid,9)
> > os.wait()
>
> > but this is not working for me... :( any clues?
>
> >> P/S: I'm not sure why the python process survives, and I think your use
> >> of "zombie" is not correct (afaik a zombie is an exited process whose
> >> parent hasn't called wait() yet)
>
> > This is what I have:
>
> > localhost cgi-bin # ps ax | grep py
> > 11853 ? Z 0:00 [python2.6]
> > 12029 pts/1 S+ 0:00 grep --colour=auto py
>
> > The 'Z' you see there stands for Zombie
>
> How about:
>
> process.kill() # New in Python 2.6
>
> or:
>
> os.kill(process.pid, 9)
>
> then:
>
> process.wait()
>
> or:
>
> os.waitpid(process.pid, 0)
HI MRAB,
Thanks for your suggestion, changed my code now to:
process=subprocess.Popen(commandlist)
...
...
process.kill()
os.waitpid(process.pid, 0)
but it's not killing the process running. it still runs in the
background and i don't see any errors, we're running python 2.6.4
any more clues?
Thanks,
Ron
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to kill a subprocess
On Sep 10, 11:45 am, Christian Heimes wrote: > Am 10.09.2010 19:51, schrieb cerr: > > > Thanks for your suggestion, changed my code now to: > > > process=subprocess.Popen(commandlist) > > ... > > ... > > process.kill() > > os.waitpid(process.pid, 0) > > but it's not killing the process running. it still runs in the > > background and i don't see any errors, we're running python 2.6.4 > > any more clues? > > It's not an issue with your Python process but with its parent process. > The parent process has to call the OS's waitpid() function with the PID > of the Python process in order to reap it. Please show us how you are > starting and controlling the Python process in your PHP code. But I wanna kill the child process I start from my python code. It's like PHP -> Python -> Perl and when the connection PHP -> Python seems to work well! -- http://mail.python.org/mailman/listinfo/python-list
Re: how to kill a subprocess
On Sep 10, 12:18 pm, Christian Heimes wrote: > Am 10.09.2010 20:56, schrieb cerr: > > > But I wanna kill the child process I start from my python code. > > It's like > > PHP -> Python -> Perl > > > and when the connection PHP -> Python seems to work well! > > You have said that the Python process becomes a zombie process. This > clearly tells me that the issue is in your PHP script. > Seehttp://en.wikipedia.org/wiki/Fork-exec No, the Perl becomes the zombie. -- http://mail.python.org/mailman/listinfo/python-list
socket.error: [Errno 98] Address already in use
Hi There, I get a socket error "[Errno 98] Address already in use" when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() Shouldn't that clean it all up properly? Thanks for hints & suggestions! Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sep 15, 5:51 pm, "[email protected]" wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > El 15/09/2010 20:58, Grant Edwards escribió: > > > > > On 2010-09-15, cerr wrote: > > >> I get a socket error "[Errno 98] Address already in use" when i > >> try to open a socket that got closed before with close(). How > >> come close() doesn't close the socket properly? My socket code : > > >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, > >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > > At what line does the error occur? > > > To what does the phrase "open a socket" refer? > > > Have you tried the usual solution of setting the SO_REUSEADDR > > option on the socket before calling bind? > > >http://www.google.com/search?q=socket+%27address+already+in+use%27 > > Maybe, you have any other proccess in your system using your listen > port, for example apache... Nope negative, I have one process on my system only that occupies port 1514. > > - -- > _ _ _ _ _ _ _ _ _ _ _ > Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / > Telf: +34 637 058 813 / / / / / /_ / / / / / / > Correo-e: [email protected] _ / / / / / _ _ _/ / / / / > Msn: [email protected] / /_ / / / / / / / /_/ / > ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_/ /_ _ _/ > Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ > > iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ > 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP > =MoYK > -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.error: [Errno 98] Address already in use
On Sep 15, 11:58 am, Grant Edwards wrote: > On 2010-09-15, cerr wrote: > > > > > > > I get a socket error "[Errno 98] Address already in use" when i try to > > open a socket that got closed before with close(). How come close() > > doesn't close the socket properly? > > My socket code : > > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > s.bind((host, port)) > > s.listen(1) > > ... > > ... > > ... > > while loop: > > conn, addr = s.accept() > > while conn and loop: > > ... > > ... > > ... > > conn.close() > > At what line does the error occur? The whole message I get looks like: Traceback (most recent call last): File "./checkGPIO.py", line 148, in main() File "./checkGPIO.py", line 75, in main s.bind((host, port)) File "", line 1, in bind socket.error: [Errno 98] Address already in use Where line 75 contains following: s.bind((host, port)) > > To what does the phrase "open a socket" refer? create a listening socket...? > Have you tried the usual solution of setting the SO_REUSEADDR option > on the socket before calling bind? yep, that did it for me, thanks a lot! :) > http://www.google.com/search?q=socket+%27address+already+in+use%27 Google's your friend if you can read ;) > > -- > Grant Edwards grant.b.edwards Yow! I own seven-eighths of > at all the artists in downtown > gmail.com Burbank! -- http://mail.python.org/mailman/listinfo/python-list
upload file using post to https server
hi,
I've been unsucessfully trying to upload a file using POST to an https
server.
I've succesfully logged in and gotten to read something from the
server..
I have come up with something like this:
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password(realm='Configuration Software',
uri=url,
user='admin',
passwd='**')
opener = urllib2.build_opener(authinfo)
pagePtr = opener.open(url)
dataRead = str(pagePtr.read())
#Look for 'Software Upload' in the page
if( "Software Upload" in dataRead ):
print "FOUND Software Upload in string..."
else:
print "Software Upload page not found. Exiting..."
sys.exit()
values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' }
try:
data = urllib.urlencode( values )
req = urllib2.Request( url, data )
#response = urllib2.urlopen( req )
response = opener.open( req )
the_page = response.read()
#print the_page
except Exception,detail:
print "err ",detail
#Look for 'file must be efs' in the page
if( "file must be efs" in the_page ):
print "file must be efs. Exiting..."
sys.exit()
else:
print "OK"
But the file doesn't seem to get there correctly. What I wanna do, is
mocking the upload from the html site with my python script the
html looks something like this:
Thanks for your hints and suggestions on how I have to go about this!
Ron
--
http://mail.python.org/mailman/listinfo/python-list
