SEARCH YOUR SOLUTION HERE  

get wikipedia source failed (urrlib2)


I'm trying to get wikipedia page source with urllib2:
usock = urllib2.urlopen("http://en.wikipedia.org/wiki/
Albert_Einstein")
data = usock.read();
usock.close();
return data
I got exception because HTTP 403 error. why with my browser i can't
access it without any problem

Posted On: Monday 5th of November 2012 02:37:37 AM Total Views:  455
View Complete with Replies




Related Messages:

Contextmenu in a QTreeWidget with PyQT   (127 Views)
I apologize in advance if this is not the correct forum to ask this and if someone knows a better place, please let me know. But, I am trying to create a Contextmenu (a right-click popup menu) from within a QTreeWidget. I tried setting the contextMenuPolicy to CustomContextMenu and then handling the signal customContextMenuRequested() but nothing seems to be happening. ie: self.tree = QTreeWidget() self.tree.setContextMenuPolicy(Qt.CustomContextMenu) self.connect(self.tree,SIGNAL('customContextMenuRequested()'),self.newContext) Does anyone have a sample or tutorial on how to do this One other question, whe I right click, it changes the selection in the TreeWidget, would I need to remove the handler for right clicks to get the menu
Re: Trouble getting loop to break   (110 Views)
On Nov 20, 2007 8:41 AM, Dick Moores wrote: > I'm writing a demo of the infinite series > > x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) > > It works OK for many x, but for many the loop doesn't break. Is there > a way to get it to break where I want it to, i.e., when the sum > equals the limit as closely as the precision allows > > Here's what I have: > > ======= series_xToN_OverFactorialN.py ========================== > #!/usr/bin/env python > #coding=utf-8 > # series_xToN_OverFactorialN.py limit is e**x from p.63 in The > Pleasures of Pi,e > from mpmath import mpf, e, exp, factorial > import math > import time > precision = 100 > mpf.dps = precision > n = mpf(0) > x = mpf(raw_input("Enter a non-negative int or float: ")) > term = 1 > sum = 0 > limit = e**x > k = 0 > while True: > k += 1 > term = x**n/factorial(n) > sum += term > print " sum = %s k = %d" % (sum, k) > print "exp(%s) = %s" % (x, exp(x)) > print " e**%s = %s" % (x, e**x) > print > if sum >= limit: > print "math.e**%s = %f" % (x, math.e**x) > print "last term = %s" % term > break > time.sleep(0.2) > n += 1 > > """ > Output for x == mpf(123.45): > sum = > 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942 > k = 427 > exp(123.45) = > 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942 > e**123.45 = > 410822093109668964239148908443317876138879647013995774.2951431466270782257597573259486687336246984942 > """ > ==================================================== > > This is also on the web at . > > Examples of problem x's: 10, 20, 30, 40, 100, 101 > Examples of OK x's: 0.2, 5, 10.1, 11, 33.3, 123.45 > >
Re: getElementsByTagName in ElementTree   (112 Views)
sndive@gmail.com wrote: > what's the equivalent of minidom's getElementsByTagName in ElementTree element.findall("//{namespace}tagname") Stefan
still get a using a python script in the crontab   (125 Views)
H! I have made a program that is checking if a program is running or not. If the program is not running then it must start the program again. in the /etc/crontab: * * * * * root /usr/sbin/ program_prgchk in the /usr/sbin/program_prgchk: /usr/local/bin/python /home/reseller/domeinaanvraag/program_prgchk.py in the program_prgchk.py: ---------------------------------------- import string import os import commands def checkifrunning(): line = string.strip(commands.getoutput("ps x -o pid,command | grep program_reseller.py | grep -v 'grep'")) pid = string.split(line,' ')[0] if pid''id = int(pid) return pid if checkifrunning()=='': os.system('/usr/sbin/program_reseller') # os.wait() # os.waitpid(checkifrunning(),0) os._exit(0) If I run the command /usr/sbin/program_prgchk everything works (no process) But when I use it in the crontab I get a process
How do I get triangles from a vtkPolyData object?   (88 Views)
I posted this question to the vtk mailing list last week: I've been Googling and wandering through the class references most of the afternoon, but I can't figure out how to get the triangles out of the vtkPolyData that vtkDelaunay2D produces I can get the vertex corredinates like this: delny = vtk.vtkDelaunay2D() delny.SetInput(profile) delny.SetTolerance(0.001) delny.Update() o = delny.GetOutput() vertexes = [o.GetPoint(i) for i in xrange(o.GetNumberOfPoints())] I can see that there are 84 triangles, and 'o' is a vtkPolyData object that has 84 cells and 84 polygons, so they obviously represent the triangles, but I can't figure out how to get something useful out of the cells or polys. I got multiple replies telling me that I need to make calls to o.GetNextCell(). The posters were even kind enough to include examples in C++ showing how to do a delaunay triangulation and retrieve the triangle info. However, the Python version of a vtkCellArray object (which is what's created as output from the Delaunay triangulation module) doesn't make the GetNextCell() (or GetCell()) method visible. It does have a GetNumberOfCells() object, and methods to set and insert cells, but how do I _get_ a cell -- Grant Edwards grante Yow! .. I'll make you at an ASHTRAY!! visi.com
IPv6 name resolution using getaddrinfo   (101 Views)
Hi all, To get the hostname, I can use socket.gethostbyname() but that has an inherent limitation wherein does it not support IPv6 name resolution, and getaddrinfo() should be used instead. Looking up the socket.getaddrinfo() documentation, I come to know that The getaddrinfo() function returns a list of 5-tuples with the following structure: (family, socktype, proto, canonname, sockaddr) family, socktype, proto are all integer and are meant to be passed to the socket() function. canonname is a string representing the canonical name of the host. It can be a numeric IPv4/v6 address when AI_CANONNAME is specified for a numeric host. With this information, if I try something like this: >>> for res in socket.getaddrinfo('goofy.goofy.com', None, >>> socket.AI_CANONNAME): print res (2, 1, 6, '', ('10.98.1.6', 0)) (2, 2, 17, '', ('10.98.1.6', 0)) (2, 3, 0, '', ('10.98.1.6', 0)) In the output, I see the cannoname to be always blank ''. I am not getting the IPv4 or IPv6 address as a result of using getaddrinfo(). Am I making any mistake What i am trying is a replacement function for socket.gethostbyname(hostname) which will work for both IPv4 and IPv6. # return hostbyname for either IPv4 or IPv6 address. Common function. def ipv6_gethostbyname(hostname): for res in socket.getaddrinfo(hostname,None, socket.AI_CANONNAME): fa, socktype, proto, canonname, sa = res return cannoname The above function does not seem to work. It returns blank value only.
getLabel() CD-ROM   (92 Views)
Hi list, I'm new whit pygtk library. I'm interest to know if there is a class in the graphics library that it can provide me with information about the CD-ROM label ( something similar to class KMount in the graphic library pykde[1]). At the time I'm using pycdio class[2],but i don't wont to my application by dependent on the above class mentioned.
Can we get rid of unrelated non-python posts?   (107 Views)
I joined this to read about python. Please don't respond and move to another list.
[ANN] GtkImageView 1.5.0 and PyGtkImageView 1.0.0 -- Image viewerwidget for GTK   (83 Views)
I'm pleased to finally announce GtkImageView 1.5.0. I'm even more pleased to ALSO announce PyGtkImageView 1.0.0: Description ----------- GtkImageView is a simple image viewer widget for GTK+. Similar to the image viewer panes in gThumb or Eye of Gnome. It makes writing image viewing and editing applications easy. Among its features are: * Mouse and keyboard zooming. * Scrolling and dragging. * Adjustable interpolation. * Fullscreen mode. * GIF animation support. * Ability to make selections. * Extensible using a tool system. PyGtkImageView is the Python bindings for the same thing. GtkImageView Download --------------------- Subversion: svn co http://publicsvn.bjourne.webfactional.com/gtkimageview Tarball: http://trac.bjourne.webfactional.com...w-1.5.0.tar.gz API doc: http://trac.bjourne.webfactional.com...mageview-docs/ PyGtkImageView Download ----------------------- Subversion: svn co http://publicsvn.bjourne.webfactiona...pygtkimageview Tarball: http://trac.bjourne.webfactional.com...w-1.0.0.tar.gz API doc: http://trac.bjourne.webfactional.com...mageview-docs/ PDF: http://trac.bjourne.webfactional.com...-1.0.0-api.pdf Project website: http://trac.bjourne.webfactional.com Examples -------- Here is the canonical example for using the widget:: #include #include ... GtkWidget *view = gtk_image_view_new (); GtkWidget *scroll = gtk_image_scroll_win_new (GTK_IMAGE_VIEW (view)); /* Where "box" is a GtkBox already part of your layout. */ gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file ("someimage.png", NULL); gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (view), pixbuf, TRUE); Same thing using PyGtkImageView:: import gtk import gtk.gdk import gtkimageview view = gtkimageview.ImageView() scroll = gtkimageview.ImageScrollWin(view) # Where "box" is a gtk.Box already part of your layout. box.pack_start(scroll) pixbuf = gtk.gdk.pixbuf_new_from_file("someimage.png") view.set_pixbuf(pixbuf) Future ------ * Perl bindings. * Gtk# bindings. * Haskell bindings. -- mvh Bjrn
os.path.getmtime() and compare with a date type   (142 Views)
I am new to python and are tryint to write a simple program delete log files that are older than 30 days. So I used os.path.getmtime(filepath) and compare it with a date but it does not compile. threshold_time = datetime.date.today() - datetime.timedelta(days=30) mod_time = os.path.getmtime(file_path) if( mod_time < threshold_time): #delete file However the interpreter complains at the if line, say "can't comapre datetime.date to int How can I covert one of them to make it work Thank you!
Half off topic, getting python development lib from mingw   (98 Views)
Hi . I'm using python 2.3 on XP. At the moment, I might add, I cannot change any of these: I cannot move back to linux, and I cannot use a higher version of python. Trying to install sip 4.7, using gcc version 3.4.2 (mingw-special), created this error: siplib.o:siplib.c.text+0x17): undefined reference to `_imp__PyType_Type' that led me to understand, that I just didn't install the mingw port of python development libs. That's cool, but I just can't find it anywhere. Anyone has a link
Re: Can you use -getattr- to get a function in the current module?   (103 Views)
Alex, Gabriel,
Re: getting serialized data into and out of a database   (136 Views)
En Mon, 29 Oct 2007 19:07:18 -0300, Michael Pelz Sherman escribi: > I'm having a devil of a time getting serialized data into and out of a > database (MySQL in this case) using python and MySQLdb. > > I have some C code that has its own serialization/deserialization > functions, which we've wrapped using SWIG. > > I am able to save the serialized C structs to disk but when I try to > write the exact same data to MySQL and pull it back out, I'm getting > some strange results. The data comes back looking like this: > > array('c', '\x01r\x01\x00\x...) > > Is this a python buffer, or what How can I access the data in there > I've tried using [1] but that doesn't seem to work. It's an array of characters You can write it to disk again using its tofile() method -- Gabriel Genellina
get directory and file names   (99 Views)
I am working with Python 2.5 on Windows XP (SP2). How can I traverse a folder, loop through a list of files and get their file name and extension in an elegant, pythonic way Thank you.
i need to get orkut (google) data without gdata, pls help!!!!   (125 Views)
hi,i am making a plugin for my app ( insert.clappings() ) and right now i am in some serious problem. i need a way to authenticate myself into orkut.com, get a session cookie , open a bunch of files, and make rss out of them! i can handle the make rss part. some of u might know about gdata for python (it exists , found out today on python.org) but it doesnt support the orkut service moreover i just need to get data not send it. i had been trying to getinto orkut for a while, (actually i was writing a urllib http handler) but i could not handle the cookie dance that google was playing with me. my eyes are paining right now AND I NEED SOME HELP FROM U GUYES (not how to rest my eyes lol but how to login to orkut!) anyone who has ever done this or could explain how google plays the cookie dance! SKI (giving my eyes some rest)
Xinetd & python server script. problem to get data from from client   (160 Views)
I wrote simple script to test communication: When i connect via telnet like: "telnet localhost 51423" the server is working send and receive information. but when i connected to him via client scrip so client script receive messages from server but server doesn't receive message from client. In xinetd.conf and servers conf file "only_from = 0.0.0.0/0" already choosen. What can i do Here below are my client and server: Thank you Server: #!/usr/bin/env python # example import sys import os print "Wellcome" print "please enter the string" sys.stdout.flush() line = sys.stdin.readline().strip() print "You entered %d characters." % len(line) sys.stdout.flush() client: import sys import string import os import time import socket import popen2 PORT = 51423 HOST = ""#sys.argv[1] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print "Connected from:", sock.getsockname() print "Connected to:",sock.getpeername() while 1: print "waiting" result = sock.recv(1024) print result sock.send('foo') print "Sent: foo" if result == 3: break
getopt with negative numbers?   (190 Views)
Is there an easy way to use getopt and still allow negative numbers as args I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including negative numbers into a separate sequence and ignore the (now empty) args list returned by getopt, but it would seem this is such a common requirement that there would be an option to treat a negative value as an argument. Note that this is only a problem if the first non-option is a negative value, since getopt stops processing options as soon as it identifies the first argument value. Alternatively, does optparse handle this I haven't used optparse (I know it is more powerful and OO, but you tend to stick with what you know, especially when it is part of my normal python programming template), but if it handles negative numbers I'm willing to learn it.
Class for custom Tkinter widget--difficulty   (95 Views)
I'm trying to create a custom Tkinter widget class, and I'm having some difficulty getting it set up properly. The class is called MacToolbar, saved in its own module MacToolbar.py, and imported with this statement: import MacToolbar Here is the relevant portion of the class: ###relevant class code class MacToolbar: def __init__(self, master): self.tk.call("package", "require", "macsearchfield") self.tk.call('package', 'require', 'tile') def create(self): self.baseframe = Tile.Frame(self, master) self.baseframe.pack(side='top', fill='both', expand='no') def toolbar(self): self.create() self.newframe = Tile.Frame(self.baseframe) self.newframe.pack(fill='both', expand='yes') self.buttonframe = Tile.Frame(self.newframe) self.buttonframe.pack(side='top', fill='both', expand = 'yes') I'm a bit confused on how to call a class that is imported via a module. Both approaches I try produce errors: The first approach: self.topframe = MacToolbar.toolbar(self.mainframe) yields this error: AttributeError: 'module' object has no attribute 'toolbar' The second approach: self.topframe = MacToolbar.MacToolbar.toolbar(self.mainframe) yields this error: TypeError: unbound method toolbar() must be called with MacToolbar instance as first argument (got Frame instance instead) I was expecting to be able to use the standard Class.Method notation in calling MacToolbar class methods, but it appears that this does not work at all: that's what I see in the first error above. Instead I have to use Module.Class.Method notation I've never seen this before. Can someone point out what I am doing wrong, either in the construction of the class, the way it's imported, or in how I'm calling methods -- Kevin Walzer Code by Kevin http://www.codebykevin.com
Re: Can you use -getattr- to get a function in the current module?   (112 Views)
En Mon, 03 Sep 2007 20:13:43 -0300, Sergio Correia escribi: > # Module spam.py > > import eggs > > print getattr(eggs, 'omelet')(100) > > That is, I just call the function omelet inside the module eggs and > evaulate it with the argument 100. > > But what if the function 'omelet' is in the module where I do the > getattr (that is, in spam.py). If I do any of this Use globals(): print globals()['omelet'](100) (Of course this only makes sense when using a variable instead of 'omelet'...) -- Gabriel Genellina
Tkinter pack_forget() and destroy()   (78 Views)
When I am done with a widget that is packed in a Frame, is it safe to call destroy() method on the widget after calling its pack_forget() or grid_forget() method --