Proxy connection with Python

2013-06-25 Thread bevan jenkins
Hello,

I have an issue that has been frustrating me for a while now.

This is an update of a crosspost
(http://stackoverflow.com/questions/16703936/proxy-connection-with-python)
which I made over a month ago.

I have been attempting to connect to URLs from python. I have tried:
urllib2, urlib3, and requests. It is the same issue that i run up
against in all cases. Once I get the answer I imagine all three of
them would work fine.

The issue is connecting via proxy. I have entered our proxy
information but am not getting any joy. I am getting 407 codes and
error messages like: HTTP Error 407: Proxy Authentication Required (
Forefront TMG requires authorization to fulfill the request. Access to
the Web Proxy filter is denied. )

I think that this also stops me using pip to install (at least from
remotes ).  I get 'Cannot fetch index base URL
http://pypi.python.org/simple/";.  I end up using git to clone a local
copy of the repo and install from that.

However, I can connect using a number of other applications that go
through the proxy, git and pycharm for example. When I run git config
--get htpp.proxy it returns the same values and format that I am
entering in Python namely:

http://username:password@proxy:8080

An example of code in requests is

import requests
proxy = {"http": "http://username:password@proxy:8080"}
url = 'http://example.org'
r = requests.get(url,  proxies=proxy)
print r.status_code

Thanks for your time and any suggestions gratefully received.
-- 
http://mail.python.org/mailman/listinfo/python-list


Tree structure

2011-07-25 Thread Bevan Jenkins
Hello,

I am trying to create a tree structure for use with a PyQt QTreeView.
But first I need to get my head around how to create the tree
structure.  I have a dictionary (for testing purposes) but I will
later use a table via sqlalchemy.

The use case is hydrology, so I  would like to have a hydrologically
connected river tree, in which you can browse upstream from the sea
(making choices) or downstream from any named hydrological feature.
Each key flows into its value pair. myrivers =
{"river":"flows_into"}.  An example is below:

myrivers = {"little stream":"sea",
"mountain stream":"lake",
"lake":"big river",
"cold spring":"big river",
"big river":"sea"
"sea":""}

I would like the tree to look like (if the formatting works). so
you can browse downstream from each named river but also upstream from
the sea picking which direction to go.

little stream
sea
mountain stream
lake
big river
sea
lake
big river
sea
cold spring
big river
sea
big river
sea
sea
little stream
big river
lake
mountain stream
cold spring

<>
So every key is a parent.  For all keys that have a value (not ""),
the value is the child and is then used as a parent to get the next
child until the sea and a value of "" is reached.  For the sea this is
reversed, that you find all rivers that flow into the sea and then all
rivers that flow into them.


Any thoughts about how to acomplish this will be much appreciated,
Bevan



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tree structure

2011-07-26 Thread Bevan Jenkins
On Jul 26, 8:46 pm, Peter Otten <__pete...@web.de> wrote:
> Bevan Jenkins wrote:
> > Hello,
>
> > I am trying to create a tree structure for use with a PyQt QTreeView.
> > But first I need to get my head around how to create the tree
> > structure.  I have a dictionary (for testing purposes) but I will
> > later use a table via sqlalchemy.
>> SNIP<<
> > Any thoughts about how to acomplish this will be much appreciated,
> > Bevan
>
> If you turn the values into lists you can use the same function for both
> trees:
>
> INDENT = " " * 4
>
> def print_tree(lookup, node=None):
>     def _tree(node, level):
>         print "%s%s" % (INDENT * level, node)
>         for node in lookup.get(node, ()):
>             _tree(node, level+1)
>
>     if node is None:
>         for node in lookup:
>             _tree(node, 0)
>     else:
>         _tree(node, 0)
>
> def reversed_dict(tree):
>     reversed_tree = {}
>     for key, values in rivers.iteritems():
>         for value in values:
>             reversed_tree.setdefault(value, []).append(key)
>     return reversed_tree
>
> if __name__ == "__main__":
>     rivers = {
>         "little stream": "sea",
>         "mountain stream": "lake",
>         "lake": "big river",
>         "cold spring": "big river",
>         "big river": "sea",
>         "see": ""}
>
>     rivers = dict((k, [v]) for k, v in rivers.iteritems() if v)
>     print_tree(rivers)
>     print "---"
>     print_tree(reversed_dict(rivers), "sea")- Hide quoted text -
>
> - Show quoted text -

Peter,
Thank you that does what I need!  Now I just need to incorporate into
PyQt but that shouldn't be too hard...

Macro,
I need to look into lxml in the coming months, so I might revisit this
then.
-- 
http://mail.python.org/mailman/listinfo/python-list


writing results to array

2007-12-03 Thread Bevan Jenkins
Hello,

I have recently discovered the python language and am having a lot of
fun getting head around the basics of it.
However, I have run into a stumbling block that I have not been able
to overcome, so I thought I would ask for help.

I am trying to import a text file that has the following format:
02/01/2000 @ 00:00:00   0.983896 Q10  T2
03/01/2000 @ 00:00:00   0.557377 Q10  T2
04/01/2000 @ 00:00:00   0.508871 Q10  T2
05/01/2000 @ 00:00:00   0.583196 Q10  T2
06/01/2000 @ 00:00:00   0.518281 Q10  T2
when there is missing data:
12/09/2000 @ 00:00:00Q151 T2
13/09/2000 @ 00:00:00Q151 T2

I have cobbled together some code which imports the data.  The next
step is to create an array in which each column contains a years worth
of values.  Thus, if i have 6 years of data (2001-2006 inclusive),
there will be six columns, with 365 rows (not all years have a full
data set and may only have say 340 days of data.

In the code below
print answer[j,1] is giving me the right answer but i can't write it
to an array.
any suggestions welcomed.


This is what I have:
flow=[]
flowdate=[]
yeardate=[]
uniqueyear=[]
#flow_order=
flow_rank=[]
icount=[]
p=[]

filename=r"C:\Documents and Settings\bevanj\Desktop\flow_duration.tsf"
linesep ="\n"

# read in whole file
tempdata = open( filename).read()
# break into lines
tempdata = string.split( tempdata, linesep )
# for each record, get the field values
for i in range( len( tempdata)):
# split into the lines
fields = string.split( tempdata[i])
if len(fields)>5:
flowdate.append(fields[0])
list =string.split(fields[0],"/")
yeardate.append(list[2])
flow.append(float(fields[3]))
answer=column_stack((flowdate,flow))

for rows in yeardate:
   if rows not in uniqueyear:
  uniqueyear.append(rows)

#print answer[:,0]   #date
flow_order=empty((0,0),dtype=float)
#for yr in enumerate(uniqueyear):
for iyr,yr in enumerate(uniqueyear):
for j, val, in enumerate (answer[:,0]):
flowyr=string.split(val,"/")
if int(flowyr[2])==int(yr):
print answer[j,1]
#flow_order =





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: writing results to array

2007-12-04 Thread Bevan Jenkins
Thank you all very much.

Firstly for providing an answer that does exactly what I require.  But
also for the hints on the naming conventions and the explanations of
how I was going wrong.

Thanks again,
b


-- 
http://mail.python.org/mailman/listinfo/python-list