472,790 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 software developers and data experts.

problem occurs with replaced values using fileinput

Hi All,

I am able to use urlib2 through proxy. I give proxy credentials and use
# Set the Proxy Address
proxy_ip = "10.0.1.1:80"

proxy_user = 'senthil_or'
proxy_password_orig='password'
proxy_password = urllib.quote(proxy_password_orig,"")

# Setup the Proxy with urllib2

proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' +
PROXY_IP
#proxy_url = urllib.quote(proxy_url_add)
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHan dler)
urllib2.install_opener(opener)

--
Now, I have decided in my program, I shall give a Configfile.txt to
users who can enter the proxy details and I shall substitute the
details in the script;

#FILE: Configfile.txt
# Provide the Proxy Details
PROXY_IP: 10.0.1.1
PROXY_PORT: 80
PROXY_USER: senthil_or
PROXY_PASSWORD: password

#Config Parsing function.

def configParsed():
"""Parse the Configfile.txt"""
configparser = ConfigParser()
configparser.read('ConfigFile.txt')
settings = {}
settings['PROXY_IP'] = configparser.get('PROXY','PROXY_IP')
settings['PROXY_PORT'] =
configparser.get('PROXY','PROXY_PORT').strip()
settings['PROXY_USER'] = configparser.get('PROXY','PROXY_USER')
settings['PROXY_PASSWORD'] =
configparser.get('PROXY','PROXY_PASSWORD')
return settings

Now, in my script I do a replacement of values in the script:

FILE BEFORE Replacement:
# Set the Proxy Address
proxy_ip = "PROXY_IP:PROXY_PORT"

proxy_user = 'PROXY_USER'
proxy_password_orig='PROXY_PASSWORD'
proxy_password = urllib.quote(proxy_password_orig,"")
# Setup the Proxy with urllib2
proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' +
proxy_ip
#proxy_url = urllib.quote(proxy_url_add)
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHan dler)
urllib2.install_opener(opener)

# Replacing Functions:
def replaceProxy(settings):
'''Replace the Proxy Credential values'''
for k,v in settings.items():
for line in fileinput.input('src' + os.sep+'file.py',inplace=1):
print line.replace(k,v),
return
The problem, I am facing is, when I use a script to replace certain
variables with config file based values, the urllib2 is failing!! It is
not able to get the correct credentials to open the proxy!
I debuged and derived at the conclusion at there is something wrong
with replaceProxy(settings) function I am using:
1) Either with for k,v in settings.items()
2) OR with fileinput.input and print line.replace(k,v),

The output file with replaced values looks perfectly fine to human
eyes! I dont know what is happening with automatic replacement of
values which is failing my program.

Has anyone faced this kind of scenario before?
Need your help in solving this.

Thanks,
Senthil

Dec 2 '06 #1
0 1509

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: calmar | last post by:
Hi all, I would like to use python for a replacement for some binutils. I would like to be able to pipe things into python. Actually I would not like writing a 'script' to handle the input, but...
4
by: Ben Rf | last post by:
Hi I'm new to programming and i'd like to write a program that will parse a list produced by md5summer and give me a report in a text file on which md5 sums appear more than once and where they...
15
by: Sander Tekelenburg | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The HTML specs speak of "replaced" and "non-replaced" elements, yet for the life of me I can't find an explanation of what "replaced" is supposed...
11
by: Ian Bell | last post by:
Apologies for the last post; got the topic wrong. What is the current thinking on the best way to solve the shared data problem i.e. accesssing a shared variable in a non atomic way can give...
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
8
by: erbrose | last post by:
Hey all, still a newbie to perl and programming and still needing some advice.. I have a ".CSV" table that I need to do some (rounding) manipulation on. the table looks something like this.. (the...
3
by: Robert | last post by:
I would like to count lines in a file using the fileinput module and I am getting an unusual output. ------------------------------------------------------------------------------...
4
by: jayabalan07 | last post by:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.IO; using System.Security.Cryptography;...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.