novice20 17 Junior Poster

hi,

using ftplib.storbinary(), i am able to successfully upload files of size 60KB, but not of size 7,218 KB and also 26 KB...

I am wondering why is this happening??? should file sizes be a multiple of 10...or what is the actual problem???????????

any reply would be greatly helpful.......

I am getting the following error message:

500 sorry file is not supported for Uploading

novice20 17 Junior Poster

please do reply.... this is killing me :( :( :(

filename = raw_input("Enter the file location")
filename = os.path.abspath(filename)
.............

ftp.storbinary("STOR %s"%filename,open(filename,"rb"))
...

why is it giving me no such file or directory error message, when it does exist??? on windows :( :(

novice20 17 Junior Poster

Thank you Gribouillis .

novice20 17 Junior Poster

Hi all,
i have different modules developed so far, and a main script needs to call the modules based on user's choice.

will doing like this work??


using raw_input(), i wait for user choice, and once a choice is made, corresponding module is called.

if main.py, does an 'import xxx.py' actually run the script xxx.py or has it to be done with subprocess.call()??

novice20 17 Junior Poster

ye i got what u were saying raptr_dflo :)
i changed it to:

#-- if the ports are mapped properly
            #-- if the dictionary has key 
            if(map_dict1.has_key(int(MIO_outports1[i]))):
                #-- if MIO outport is properly mapped to Exp inport(as defined in dictionary)
                if(map_dict1[int(MIO_outports1[i])] == int(Exp_map_inport[i]) ):
                    flag = 1
            elif(map_dict2.has_key(int(MIO_outports1[i]))):
                if(map_dict2[int(MIO_outports1[i])] == int(Exp_map_inport[i])):
                    flag = 1
            else:
                flag = 0

n it's working .. thank you :)

novice20 17 Junior Poster

thanks raptr_dflo, but what I say is the key is present in 'map_dict2' so, why is the control not getting passed to the 'elif' part,?? when key is not present in 'map_dict1' it should check 'map_dict2' right??

novice20 17 Junior Poster

Hi all,

Here is a part of my code:

#-- if the ports are mapped properly
            if(map_dict1[int(MIO_outports1[i])] == int(Exp_map_inport[i]) ):
                flag = 1
            elif(map_dict2[int(MIO_outports1[i])] == int(Exp_map_inport[i])):
                flag = 1
            else:
                flag = 0

But I am not able to navigate to the 'elif' part. I am getting :

if(map_dict1[int(MIO_outports1[i])] == int(Exp_map_inport[i]) ):
KeyError: 596

but my key '596' is present in 'map_dict2'. Why am I not able to go to the elif part?? where am i going wrong??

novice20 17 Junior Poster

Okkk.... got it now.. thank u tonyjv :)

novice20 17 Junior Poster

Thanks a lot to all those who have been posting reply to my threads and helping me throughout my projcet :) I would love to add reputation points to many, but unfortunately am not getting how to do it on forum :(

TrustyTony commented: You have manners +13
novice20 17 Junior Poster

@ Gribouillis

Thank you.. yes... i typed in list2 wrongly here, but that was not the problem. Thanks for the solution :)

novice20 17 Junior Poster

ok....
any other ways to do what I want?

novice20 17 Junior Poster

@ tonyjv
Thank you! I have python version 2.4.1 ,can that be posing the problem?

novice20 17 Junior Poster

Hi,
I want to do something like this:
I have two lists:

list1 = range(6)
list2 = range(10,15)

i want a dictionary like this:

adict ={0:10,
1:11,
2:12,
3:13,
4:14,
5:15
}

I did the following:

list1 = range(6)
list2 = range(10,15)
adict = dict(zip(list1,list2))

i get :
TypeError: list objects are unhashable
it didn't work.. any help pls..

novice20 17 Junior Poster

Thanks tons Gribouillis :) i converted the return value of pysnmp into python int. and the error, i suppose was caused due to system level issue. I had set some different value for a parameter of the system card. But, it didn't strike my mind... sorry for having posted this query, but thanks for guiding me in the right direction :)

novice20 17 Junior Poster

i think it is the problem with data types. am not sure :( how can i convert a result of pysnmp get into an unsigned char??

unsigned char, signed, unsigned int, unsigned char array... do all these things differ and cause the code to go astray....

there is no way to predefine data type of any variable right?

novice20 17 Junior Poster

Ok :)

I used the following:

import array
bit_map_len = array.array('B',[0]*PORT_MAP_LEN)

still it is giving the error, now after 513 runs...

no I am not changing the size anywhere, and not accessing index out of interval :)

novice20 17 Junior Poster

Hello,
can anyone help me regarding how this can be done?

I need to declare an 'array' which has 95 indices, and each entry holds 8 bits each of data.

am doing this with:

PORT_MAP_LEN = 764/8

bit_map_len = [0]*PORT_MAP_LEN


but it is giving me list index out of range error, while accessing bit_map_len[] sometimes after 1 run, sometimes after 10, 150, 460, 760 runs and so on(i get this error randomly).
anyone pls help me out

novice20 17 Junior Poster

Thank you vegaseat :)

novice20 17 Junior Poster

Hi all,
Is there any way to do forward referencing or function prototyping in python..?
Being an interpreted language, is lack of forward referencing a drawback of python?

novice20 17 Junior Poster

pls... I am seeking out some help......

novice20 17 Junior Poster

Hi all,
I need to set some variables via Pysnmp which take 'unsigned int' only.
Is python int by default a 32 bit- signed int? How do I convert it into 16 and 8 bit- unsigned ints? I need to read two registers consequently( which are of 8 bits each) and both of them together give me the desired result.

Can i just convert the result of snmp 'get' into a string, concatenate two strings and later convert it back to int using int()?

any help pls...

novice20 17 Junior Poster

Hi all...

I am trying to upload 4 files on a local disk, onto a remote ftp server. All of them are in the same folder(in local machine).
I am using the storbinary function of ftplib.

Following are the file sizes:

1-- 70 KB
2-- 60 KB
3-- 73 KB
4-- 8,100 KB

The first 3 files get uploaded successfully, but while trying to upload the 4th file, an ftplib.error_perm exception is thrown, which says "500, sorry file is not supported for uploading"

I don't think there is any permission constraint, since the first three images get uploaded without problem, and all of them are in the same folder.

Is there any limit on file size that can be uploaded by storbinary()??

novice20 17 Junior Poster

ok... thanks Grib...
before using repr(), I was getting some unrecognizable string.. something like four squares!!

U guided me in the right direction... Thanks a lot :)

novice20 17 Junior Poster

Grib....

repr() of the value gives me:

IpAddress('0.0.0.0')

:)

novice20 17 Junior Poster

using pysnmp I am querying a variable which gives the IP address. I want to check that address.

I do the following

...........
............
.............
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxx', 'yyy', 1), cmdgen.UdpTransportTarget((addr,161)), ((1,3,6,1,4,1,18489,1,2,2,2,9,30,0)))
print"Error on GET for ccmSDIDULinkUtilEastRemoteIP -%s,%s%(errorIndication,errorStatus)
print varBinds
print varBinds[0][1]

i get the following:

Error on GET for ccmSDIDULinkUtilEastRemoteIP -None,0
[(ObjectName('1.3.6.1.4.1.18489.1.2.2.2.9.30.0'), IpAddress('0.0.0.0'))]

varBinds[0][1] is giving me some wierd value.. some unrecognizable characters..which i can't even copy, paste.. It's driving me nuts :'(

Pls.. help........

novice20 17 Junior Poster

Ok...

ping address -t pings indefinitely until we close the terminal

novice20 17 Junior Poster

@ Gribouillis:
can the above be used??

novice20 17 Junior Poster

ok....

thanks a lot.. yes i'll do as u said... I have written a simple code which serves my purpose. It may seem very crude, but it's helping me.. here it is:

os.system("ping 192.168.5.181> ping_out.txt")

fp=open("ping_out.txt","r")

if((fp.readlines()[9].split(",")[2])== ' Lost = 0 (0% loss)'):
    print"***Ping Succeeded.....Host reachable***"
else:
    print "***Ping Failed.....Host not reachable***"
novice20 17 Junior Poster

This is the code:

#!/usr/bin/python

import subprocess
def main():
    class Command(object):
        #-- _init_() is first piece of code executed in a newly created instance of class
	#-- self refers to the current instance of the class
	def _init_(self,command):
            self.command = command
	def run(self, shell= True):
            process = subprocess.Popen(self.command,shell = shell,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
	    self.pid = process.pid
	    self.output, self.error = process.communicate()
	    self.failed = process.returncode
	    return self
	def returncode(self):
            return self.failed

    com = Command("ping 192.168.5.183").run()
    print com.output
    print com.error
    print com.failed

if __name__ == '__main__':
    main()

and this is the trace back:

Traceback (most recent call last):
  File "D:\Python24\ping.py", line 25, in -toplevel-
    main()
  File "D:\Python24\ping.py", line 19, in main
    com = Command("ping 192.168.5.183").run()
TypeError: default __new__ takes no parameters
novice20 17 Junior Poster

one more doubt..
what is com.failed returning here?? can u pls explain ?

am am getting this error message:

TypeError: default __new__ takes no parameters

what is it saying?

novice20 17 Junior Poster

ok... I'll try doing that.. once again thanks a lot for the help :)

novice20 17 Junior Poster

@Gribouillis:
Thanks a lot :)
my further question, I have the output string now, but I don't want manual interruption to check the output, i.e., script itself should read the output and decide whether the host is up or not??

any way to do this?

novice20 17 Junior Poster

hi all..

I need to issue a 'ping' to an ip address via my script and check whether it is up?

can I issue it using os.system? can I capture the output and analyze to see if the host is up??

novice20 17 Junior Poster

@ tonyjv

thanks. Yes it's the exact code from Python documentation. Yet I am getting the duplication of messages on console, but not in the log file

novice20 17 Junior Poster

where have all my saviours gone? :(

novice20 17 Junior Poster

no inputs? :(

novice20 17 Junior Poster

Hi,

I get the log messages 'twice' on the console and only once in the log file.

Can any one tell me the reason for this duplication on console?

here is how I have set the logger:

import logging
#--set up logging to file
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%Y-%m-%d %H:%M',
                    filename='linkconfig_log.txt',
                    filemode='a')
                    
#--defines a handler which writes DEBUG messages or higher to sys.stdout
console=logging.StreamHandler()
console.setLevel(logging.DEBUG)


#--setting a format which is simpler for console use
formatter=logging.Formatter('%(levelname)-8s %(message)s')

#--tell the handler to use this format
console.setFormatter(formatter)

#--add handler to the root logger
logging.getLogger('').addHandler(console)

help please

novice20 17 Junior Poster

Hey... I had done an indentation mistake. Such a dumbo i am :) had called subprocess outside the scope of the for loop. Now it is solved.

Anyway thanks for listening :)

novice20 17 Junior Poster

Am I being very vague or silly ? :( can anyone pls help me out?

novice20 17 Junior Poster

Thanks for the reply.
I have defined the addr beforehand, which is not shown above.
I'll try to be a bit more clearer.
i have list1=
list2=
................................
................................
listn=

All the lists are of same length. these list elements are columns of a CSV file. i.e., first element from each list forms the first row of the csv file.

so, i want the first row to be set, then the next row and so on....for the no of rows present in the csv file.

all the lists are of same length. hence,

no_of_rows=len(list1)#---or len(list2),len(listn) for that matter

and before these elements are set, there are a number of checks to be made, which i have written as seperate scripts.

so I want this to happen

for n in range(no_of_rows): #for the no of rows in the csv file
#--------after various checks, set the first element in the first list
#--------do a subprocess call that sets the first element in the second list
#----within the second script do a subprocess call for the third script and so on
#-------when the first element of the nth list is set, 1 row of CSV file is set
#--proceed again as above in the same order

But now, the subprocess call in the first script is called only after all the elements in list1 are set, i.e., my purpose is not getting served. …

novice20 17 Junior Poster

anybody pls help me :(

novice20 17 Junior Poster

Hi,

I have a for loop something like:

for n in range(no_of_rows):
		#--configuring ODU Op mode
                odu_op_mod=list1[n]
        	odu_op_mode= odu_enum["%s"%odu_op_mod]        
                
                if (odu_op_mod == 'blahblah'):
                        #------------
                
                      

                elif(odu_op_mod == 'aaa'):
                        #--------
		
		elif(odu_op_mode =='xxx'):
                        #-----
		

		elif(odu_op_mod == 'yyy'):
                        #-------------------
                                



		elif(odu_op_mod == 'zzz'):
                        #-------------
                logging.info("*******************************************************************")                
		subprocess.call(['python link_config_idu12.py %s'%addr],shell=True)

I have different lists, list1 #for some mode, list2 #for some mode, i want the first item in list1 to be set followed by first item in list2 and so on.. that is why I am trying a subprocess.call() within the for loop as shown above. But, i see that what i expect is not happening. First all the elements in list1 is getting set, then all the elements in list2 and so on..

where am I going wrong??? please help me out

novice20 17 Junior Poster

I want 1.py to call 2.py.

1.py takes an Ip address as a command line argument. I am trying a 'subprocess.call()' in 1.py to call 2.py.

I have defined addr= sys.argv[1] before the main() of 1.py. I want the same address to be accessed in 2.py.

In short, 1.py should call 2.py, which in turn calls 3.py and so on, just by one command

python 1.py ipaddress and this address has to be passed on to all other scripts. how can this be done?

To add on...

i have used

subprocess.call(,shell=True) within the main of 1.py

also have defined addr=sys.argv[1] before the main() of 2.py

I know I am wrong somewhere in taking that system argument, but not able to nail it.

it is giving me the error:

self.transportAddr = (
socket.gaierror:(11001,'getaddrinfo failed')

Thanks for the patient reading!

novice20 17 Junior Poster

Hi,

in the pysnmp tutorial, I couldn't find an equivalent for snmpwalk. What can be used?

novice20 17 Junior Poster

@ snippsat:

Thanks a lot for ur patient and detailed explanation. It helped me a lot. :)

novice20 17 Junior Poster

As Gribouillis suggested, I moved pyasn1 and pysnmp to D:\Python24\ in my PC.

at command line, i used

import os
os.chdir('D:/Python24/pyasn1')
python setup.py install

it's still giving me
syntax error in line 1.

I saw that setup.py has the following interpreter line
#!/usr/bin/env python

I am not understanding where am I going wrong

novice20 17 Junior Poster

@ Gribouillis.
Thank you. I extracted the files using 7zip before putting it under site-packages.

I still got the import error.
So, I navigated to D:\Python24\Lib\site-packages\pyasn1 and just tried running the module setup.py (i.e., I gave Run module in the IDE). It showed the following error:

Traceback (most recent call last):
  File "D:\Python24\Lib\site-packages\pyasn1\setup.py", line 42, in ?
    apply(setup, (), params)
  File "D:\Python24\lib\distutils\core.py", line 137, in setup
    raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied
novice20 17 Junior Poster

Hi,

I am working with python2.4 on windows, and want pysnmp to be imported.

Have downloaded pysnmp-4.1.14a.tar.gz and pyasn1-0.0.12a.tar.gz and put it under

D:\Python24\Lib\site-packages\. Still i am getting the import error.

from pysnmp.entity.rfc3413.oneliner import cmdgen
ImportError: No module named pysnmp.entity.rfc3413.oneliner

What should I do to make pysnmp importable?

novice20 17 Junior Poster

Thanks a lot Gribouillis. I got it now :) :)

novice20 17 Junior Poster

Thanks a lot. Every input is helping me :) But, I am not clear why you mentioned about the circular import here. Does it mean that importing a function from the main module in another module leads to circular import?