Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problem with proxies

Reply
Thread Tools

Problem with proxies

 
 
Ameet Nanda
Guest
Posts: n/a
 
      10-16-2007

Hi All,

I access net using a proxy, which I have to authenticate everytime I try
to access net from my system. Now when I use urllib2.urlopen(url) , I
cant get ahead. I must provide proxy authentication , I tried reading
docs online which speak of something called as FancyUrlOpener. Now i
want to hardcode my username and password inside the script or somehow
save it.

How do I go ahead with that ??

-
Ameet



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com
 
Reply With Quote
 
 
 
 
coolman_suk@yahoo.com
Guest
Posts: n/a
 
      10-16-2007
i have never used proxies, in college it works fine dont know abt ur
wipro settings.
anyway try this http://docs.python.org/lib/urllib2-examples.html

then l8tr try this http://docs.python.org/lib/module-urllib2.html




 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      10-16-2007
> I have struggling to efficiently convert a string list to
> number. Here is my problem. I have a file that contains lines
> such as:
>
> data_1 1 1 2 3.5
>
> After I read the data from the file by using readlines(), each
> line contains a string. I use the re moduel to split the line
> into ['data_1', '1','1','2','3.5']. I want to create a
> dictionary which contains
>
> {'data_1':[1 1 2 3.5]}
>
> The problem is I coud not efficiently find a way to convert
> the string to number.
>
> Does anyone know how to create such dictionary efficiently?


Despite my Spidey-sense tingling that this is a homework
assignment, as similar forms of the question have popped up
several times in the last week, I supress it this time.

Paraphrasing Andy Dufresne, "Mr. Wang, do you trust your file?"[1]

If you don't trust the content of your file, you have to know either

1) how many columns of data to expect or
2) the type each should be (int or float)

If the same type for each is okay, you can use something like

>>> s = {}
>>> for line in file('in.txt'):

... k,v = line.rstrip('\n').split(None, 1)
... s[k] = map(float, v.split())
...
>>> s

{'data_1': [1.0, 1.0, 2.0, 3.5], 'data_4': [1.0, 1.0, 8.0, 4.5]}

However, if you want them to be the actual types that evaluating
them would give (thus the trust-your-source issue), you can use this:

>>> s = {}
>>> for line in file('in.txt'):

... k,v = line.rstrip('\n').split(None, 1)
... s[k] = map(eval, v.split())
...
>>> s

{'data_1': [1, 1, 2, 3.5], 'data_4': [1, 1, 8, 4.5]}


Both instances don't try to do anything smart with duplicate
keys, so if you want to append, Bruno Desthuilliers *just* posted
(in the last hour or so) a nice tip on this using
setdefault().append()

-tkc

[1]http://www.finestquotes.com/movie_quotes/movie/Shawshank%20Redemption/page/0.htm





 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      10-16-2007
> I am new to Python and find it very interesting

welcome to the wonderful world of Python

> so I decided to try to port a big project from matlab to
> python. To prove the value of the python, I need to find an
> python way to do it.


A good exercise for learning Python.

> The input file contains many lines of data starts with a
> label. The data lengths are not the same and the data type is
> mixed with int and float. Some lines start with comment sign #
> need to be removed from the dictionary. The mixed int and
> float really cause me trouble to convert the data efficiently.
> I will try your suggestion



Just check the results on each line as you iterate over
them...something like

results = {}
for line in file('in.txt'):
line = line.strip()
if line.startswith('#'): continue
key, values = line.split(None,1)
results[key] = map(eval, values.split())

-tkc



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem when applying Patch from issue1424152 to get https overauthenticating proxies working with urllib2 in Python 2.5 tvashtar Python 2 07-20-2009 05:58 PM
Mechanize problem with proxies Dani Pardo Ruby 0 10-23-2008 11:21 AM
A problem about proxies ZelluX Java 3 05-11-2008 11:56 AM
Proxies, anyone? mad scientist Firefox 3 10-31-2004 05:22 AM
Calling com proxies from asp.net Ryan ASP .Net 0 12-11-2003 02:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57