November 14th, 2012, 05:07 PM
Txt file access needs user id & pw
Hi, I'd really appreciate some assistance with a query i have regarding opening text files held on remote machines.
I'm a total beginner to programming and therefore Python too, so apologies if the answer to this is really obvious, it's just i've not been successful in my google or forum searches.
I have created a script to open and return data from configuration text files held on the servers in my environment, which has worked well, but what i want to do, is for the script to prompt me for an ID and PW. Certain servers are set up with different admin credentials than those I use from my PC.
I've seen some stuff on 'getpass' but not enough for me to figure out what i need to do.
Hopefully I've explained this well enough and as i say, apologies if this is blindingly obvious, but I've only just finished reading my 1st Python book (Also I'm keen to take the next step if someone can suggest some good resources).
I'm using Python 3.1.1 on XP
Thanks in advance
servername = input("Please enter the server name ")
print ("\nOpening the ntc file on Brars"+servername)
text_f = open ("//brars" + servername + "/cdrive$/bs/configs/ntc_svc_test.cfg", "r")
print("File doesn't exist, please check server name")
whole_thing = text_f.read()
print("\nClosing the ntc file on Brars"+servername)
input ("\nPress enter to exit")