[web2py] How I can use code tag with Markmin?
How I can use code tag with Markmin? Thank you. --
Re: [web2py] How I can use code tag with Markmin?
Bruno, thank you. But if I only need the simple code? code anything /code How I can do it? On Monday, January 21, 2013 9:56:35 PM UTC-6, rochacbruno wrote: `` htmlbodyHello World/body/html ``:code_html `` print hello world ``:code_python On Tue, Jan 22, 2013 at 1:50 AM, Ignacio Ocampo naf...@gmail.comjavascript: wrote: How I can use code tag with Markmin? Thank you. -- --
Re: [web2py] How I can use code tag with Markmin?
Thank you Bruno, and precodeanything/code/pre :) ? On Mon, Jan 21, 2013 at 10:09 PM, Bruno Rocha rochacbr...@gmail.com wrote: `` Your code here `` for testing: http://web2py.com/markmin -- -- Ignacio Ocampo Millán --
Re: [web2py] How I can use code tag with Markmin?
Very fun! :) On Mon, Jan 21, 2013 at 11:22 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: This works MARKMIN(text, extra={pre_with_code: lambda text: precode{0}/code/pre.**format(text)}) but is is a little dangerous since the user can do `` /code/pre scriptalert('oops!');/script precode `` The argument of text should be escaped somehow. Not sure how since you want to allow verbatim code. On Monday, 21 January 2013 22:30:51 UTC-6, rochacbruno wrote: for this I thinnk you sould use extra render. {{text = `` here is my code ``:pre_with_code}} {{=MARKMIN(text, extra={pre_with_code: lambda text: precode{0}/code/pre.**format(text)})}} Tested on shell In [4]: text = `` here is my code ``:pre_with_code In [5]: print MARKMIN(text, extra={pre_with_code: lambda text: precode{0}/code/pre.**format(text)}) precode here is my code /code/pre -- -- Ignacio Ocampo Millán --
[web2py] Query, COUNT and SUM with custom Expression
I'm working with a custom Query, I need use SUM and COUNT together, when I use: select(db.field.count(), db.field.sum()) works OK But when I use: select('COUNT(*)', 'SUM(DATEDIFF(table.field,NOW()))') raise an error I see that I can't combine more that 1 custom expressions. Any idea? --
[web2py] Re: Query, COUNT and SUM with custom Expression
Thank you Massimo! Regards. On Sunday, January 20, 2013 2:22:34 PM UTC-6, Massimo Di Pierro wrote: Doh! Fixed in trunk. Thanks for reporting this was a serious issue. On Sunday, 20 January 2013 12:27:41 UTC-6, Ignacio Ocampo wrote: I'm working with a custom Query, I need use SUM and COUNT together, when I use: select(db.field.count(), db.field.sum()) works OK But when I use: select('COUNT(*)', 'SUM(DATEDIFF(table.field,NOW()))') I print the output with _select and I see that when I use more that 1 custom expression, I get the last expression repeated, such as: SELECT ... FROM table WHERE ... SUM(DATEDIFF(table.field,NOW())), SUM(DATEDIFF(table.field,NOW())) ... If I change the order: select('SUM(DATEDIFF(table.field,NOW()))', 'COUNT(*)') I get: SELECT ... FROM table WHERE ... COUNT(*), COUNT(*) ... Any idea? --
[web2py] Bug: Query with Expression that contains space within
When I use custom expression, that contains comma within, it fails if I use an space after comma. *Example 1* --- WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, DATEDIFF(tickets.created_*on,N*OW())) colnames=['tickets.name', 'tickets.created_on', 'DATEDIFF(tickets.created_o* n,N*OW())'] --- DON'T WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, DATEDIFF(tickets.created_*on, N*OW())) colnames=['tickets.name', 'tickets.created_on', 'DATEDIFF(tickets.created_on *', '*NOW())'] *Example 2* --- WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, SUBSTRING(tickets.nam*e,5*)) colnames=['tickets.name', 'tickets.created_on', 'SUBSTRING(tickets.nam*e,5* )'] --- DON'T WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, SUBSTRING(tickets.nam*e, 5*)) colnames=['tickets.name', 'tickets.created_on', 'SUBSTRING(tickets.name*', ' *5)'] --
[web2py] Re: Bug: Query with Expression that contains comma and space within
Massimo, I see the problem, in my dal.py in _select function: def _select(self, query, fields, attributes): tables = self.tables for key in set(attributes.keys())-SELECT_ARGS: raise SyntaxError, 'invalid select attribute: %s' % key args_get = attributes.get tablenames = tables(query) for field in fields: if isinstance(field, basestring) \ and REGEX_TABLE_DOT_FIELD.match(field): tn,fn = field.split('.') field = self.db[tn][fn] for tablename in tables(field): if not tablename in tablenames: tablenames.append(tablename) if use_common_filters(query): query = self.common_filter(query,tablenames) if len(tablenames) 1: raise SyntaxError, 'Set: no tables selected' sql_f = ', '.join(map(self.expand, fields)) *self._colnames = [c.strip() for c in sql_f.split(', ')]* if query: sql_w = ' WHERE ' + self.expand(query) else: sql_w = '' sql_o = '' The problem is in: *self._colnames = [c.strip() for c in sql_f.split(', ')]* Because *sql_f* value is tickets.name, tickets.created_on, SUBSTRING(tickets.name, 5) Now, I see that in the new dal.py trunk version you have: *self._colnames = map(self.expand, fields) * It's solve the problem? I have web2py version: (2, 2, 1, datetime.datetime(2012, 10, 21, 16, 57, 4), 'stable') Regards. On Sunday, January 20, 2013 3:09:59 PM UTC-6, Massimo Di Pierro wrote: I cannot reproduce. Can you post the model? On Sunday, 20 January 2013 14:43:58 UTC-6, Ignacio Ocampo wrote: When I use custom expression, that contains comma within, it fails if I use an space after comma. *Example 1* --- WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, DATEDIFF(tickets.created_*on,N*OW())) colnames=['tickets.name', 'tickets.created_on', 'DATEDIFF(tickets.created_o*n,N*OW())'] --- DON'T WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, DATEDIFF(tickets.created_*on, N*OW())) colnames=['tickets.name', 'tickets.created_on', 'DATEDIFF(tickets.created_on*', '*NOW())'] *Example 2* --- WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, SUBSTRING(tickets.nam*e,5*)) colnames=['tickets.name', 'tickets.created_on', 'SUBSTRING(tickets.nam* e,5*)'] --- DON'T WORKS --- query = ac(tickets.id0).select(tickets.name, tickets.created_on, SUBSTRING(tickets.nam*e, 5*)) colnames=['tickets.name', 'tickets.created_on', 'SUBSTRING(tickets.name*', '*5)'] --
[web2py] Custom authentication provider
Hi, I'm working with my own authentication provider as: * auth.settings.login_form=MyAuth()*, all *works correctly*. I need an additional field from default auth_user table definition, I used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 'text')]*, works correctly (the value of this field is provided by MyAuth() to reference another system, ergo, in web2py it's would be treated as a simple text). The final schema is: CREATE TABLE auth_user( id INTEGER PRIMARY KEY AUTOINCREMENT, first_name CHAR(128), last_name CHAR(128), email CHAR(512), password CHAR(512), registration_key CHAR(512), reset_password_key CHAR(512), registration_id CHAR(512) , *employee_id* TEXT); In MyAuth() class, I have the method get_user(self), which web2py call in the login process to get user details. At the end of this method, I return: user = dict(first_name=response['attributes']['cn'][0], last_name=response['attributes']['cn'][0], username=response['attributes']['uid'][0], registration_id=response['attributes']['uid'][0], *employee_id* =response['attributes']['*employee_id*'][0]) All fields are updated correctly, except the *employee_id*, that is the additional field. *Hypothesis 1*: I don't know if web2py is updating only default fields from the auth_user table (and because employee_id are not default field, it's no updated). *Hypothesis 2*: The name of the additional field *employee_id* is malformed (because the last part _id is used to reference another table and commonly is INT type and web2py don't know how to handle this, since there is no the *employee* table). Thank you. --
[web2py] Re: Custom authentication provider
I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. I don't write/update the auth_user table in my custom class. On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote: hypothesis 2 is off the table BTW: saying that you have a method that returns a dict and stating that that method doesn't update a field lacks of the key point.. *Who*writes/updates the auth_user table in your custom class ? On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote: Hi, I'm working with my own authentication provider as: * auth.settings.login_form=MyAuth()*, all *works correctly*. I need an additional field from default auth_user table definition, I used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 'text')]*, works correctly (the value of this field is provided by MyAuth() to reference another system, ergo, in web2py it's would be treated as a simple text). The final schema is: CREATE TABLE auth_user( id INTEGER PRIMARY KEY AUTOINCREMENT, first_name CHAR(128), last_name CHAR(128), email CHAR(512), password CHAR(512), registration_key CHAR(512), reset_password_key CHAR(512), registration_id CHAR(512) , *employee_id* TEXT); In MyAuth() class, I have the method get_user(self), which web2py call in the login process to get user details. At the end of this method, I return: user = dict(first_name=response['attributes']['cn'][0], last_name=response['attributes']['cn'][0], username=response['attributes']['uid'][0], registration_id=response['attributes']['uid'][0], *employee_id* =response['attributes']['*employee_id*'][0]) All fields are updated correctly, except the *employee_id*, that is the additional field. *Hypothesis 1*: I don't know if web2py is updating only default fields from the auth_user table (and because employee_id are not default field, it's no updated). *Hypothesis 2*: The name of the additional field *employee_id* is malformed (because the last part _id is used to reference another table and commonly is INT type and web2py don't know how to handle this, since there is no the *employee* table). Thank you. --
[web2py] Re: Custom authentication provider
I see that only the first time that user login, web2py saves the employee_id. If I logout and login, and I change the employee_id value (I write this in external file to see the value), web2py does not update the field. On Tuesday, January 8, 2013 11:08:34 AM UTC-6, Ignacio Ocampo wrote: I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. I don't write/update the auth_user table in my custom class. On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote: hypothesis 2 is off the table BTW: saying that you have a method that returns a dict and stating that that method doesn't update a field lacks of the key point.. *Who*writes/updates the auth_user table in your custom class ? On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote: Hi, I'm working with my own authentication provider as: * auth.settings.login_form=MyAuth()*, all *works correctly*. I need an additional field from default auth_user table definition, I used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 'text')]*, works correctly (the value of this field is provided by MyAuth() to reference another system, ergo, in web2py it's would be treated as a simple text). The final schema is: CREATE TABLE auth_user( id INTEGER PRIMARY KEY AUTOINCREMENT, first_name CHAR(128), last_name CHAR(128), email CHAR(512), password CHAR(512), registration_key CHAR(512), reset_password_key CHAR(512), registration_id CHAR(512) , *employee_id* TEXT); In MyAuth() class, I have the method get_user(self), which web2py call in the login process to get user details. At the end of this method, I return: user = dict(first_name=response['attributes']['cn'][0], last_name=response['attributes']['cn'][0], username=response['attributes']['uid'][0], registration_id=response['attributes']['uid'][0], *employee_id* =response['attributes']['*employee_id*'][0]) All fields are updated correctly, except the *employee_id*, that is the additional field. *Hypothesis 1*: I don't know if web2py is updating only default fields from the auth_user table (and because employee_id are not default field, it's no updated). *Hypothesis 2*: The name of the additional field *employee_id* is malformed (because the last part _id is used to reference another table and commonly is INT type and web2py don't know how to handle this, since there is no the *employee* table). Thank you. --
[web2py] Re: Custom authentication provider
Yes, I only uses: auth.settings.login_form=MyAuth( param1=value1, param2=value ) It's all, I never call and writes/update in the auth_user anywhere. In gluon/tools.py login function, web2py check if they would use their login form or from a central source (line 1955) At line 2068 web2py determined that central authentication would be used. At line 2075 web2py call: user = self.get_or_create_user(table_user._filter_fields(cas_user)) At line 1724, within get_or_create_user function, after that web2py determine that the user exists: *update_keys = dict(registration_id=keys['registration_id']) #here is the BUG* I solved it with: *update_keys = dict(registration_id=keys['registration_id'], employee_id=keys['employee_id'])* So, I think that we need to update the gluon/tools.py file, to improve the update of external fields. On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote: On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote: I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. Yes, but where are you telling web2py to update the auth_user table? Can you show the code? Anthony --
[web2py] Re: Custom authentication provider
I only change the Auth function to solve this problem and to know how web2py works. I see that get_or_create_user have a second parameter with fields that will be updated. I think that if the developer uses web2py default Auth function, would be nice allow update fields through auth.settings.update_fields configuration. Is viable? To open a new ticket. Ignacio Ocampo On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote: Perhaps I misunderstand the workflow. The solution cannot be to change an Auth function to handle a specific custom field. The proper signature for the function is get_or_create_user(self, keys, update_fields=['email']) so if you want to pass employee_id to keys and expect it to update the record in case it is found you need to pass get_or_create_user(self, keys, update_fields=['email', 'employee_id']) There are two options here: 1) allow some auth.settings.update_fields to be specified so the function is called with right parameters 2) change it so that update_fields defaults to keys.keys() 2) would solve the problem automatically but it may break something. Not sure. Please open a ticket: http://code.google.com/p/web2py/issues/list but let's discuss it some more. Massimo On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote: Yes, I only uses: auth.settings.login_form=MyAuth( param1=value1, param2=value ) It's all, I never call and writes/update in the auth_user anywhere. In gluon/tools.py login function, web2py check if they would use their login form or from a central source (line 1955) At line 2068 web2py determined that central authentication would be used. At line 2075 web2py call: user = self.get_or_create_user(table_user._filter_fields(cas_user)) At line 1724, within get_or_create_user function, after that web2py determine that the user exists: *update_keys = dict(registration_id=keys['registration_id']) #here is the BUG* I solved it with: *update_keys = dict(registration_id=keys['registration_id'], employee_id=keys['employee_id'])* So, I think that we need to update the gluon/tools.py file, to improve the update of external fields. On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote: On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote: I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. Yes, but where are you telling web2py to update the auth_user table? Can you show the code? Anthony --
[web2py] Re: Custom authentication provider
I open a ticket http://code.google.com/p/web2py/issues/detail?id=1260 On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote: Perhaps I misunderstand the workflow. The solution cannot be to change an Auth function to handle a specific custom field. The proper signature for the function is get_or_create_user(self, keys, update_fields=['email']) so if you want to pass employee_id to keys and expect it to update the record in case it is found you need to pass get_or_create_user(self, keys, update_fields=['email', 'employee_id']) There are two options here: 1) allow some auth.settings.update_fields to be specified so the function is called with right parameters 2) change it so that update_fields defaults to keys.keys() 2) would solve the problem automatically but it may break something. Not sure. Please open a ticket: http://code.google.com/p/web2py/issues/list but let's discuss it some more. Massimo On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote: Yes, I only uses: auth.settings.login_form=MyAuth( param1=value1, param2=value ) It's all, I never call and writes/update in the auth_user anywhere. In gluon/tools.py login function, web2py check if they would use their login form or from a central source (line 1955) At line 2068 web2py determined that central authentication would be used. At line 2075 web2py call: user = self.get_or_create_user(table_user._filter_fields(cas_user)) At line 1724, within get_or_create_user function, after that web2py determine that the user exists: *update_keys = dict(registration_id=keys['registration_id']) #here is the BUG* I solved it with: *update_keys = dict(registration_id=keys['registration_id'], employee_id=keys['employee_id'])* So, I think that we need to update the gluon/tools.py file, to improve the update of external fields. On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote: On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote: I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. Yes, but where are you telling web2py to update the auth_user table? Can you show the code? Anthony On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote: Perhaps I misunderstand the workflow. The solution cannot be to change an Auth function to handle a specific custom field. The proper signature for the function is get_or_create_user(self, keys, update_fields=['email']) so if you want to pass employee_id to keys and expect it to update the record in case it is found you need to pass get_or_create_user(self, keys, update_fields=['email', 'employee_id']) There are two options here: 1) allow some auth.settings.update_fields to be specified so the function is called with right parameters 2) change it so that update_fields defaults to keys.keys() 2) would solve the problem automatically but it may break something. Not sure. Please open a ticket: http://code.google.com/p/web2py/issues/list but let's discuss it some more. Massimo On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote: Yes, I only uses: auth.settings.login_form=MyAuth( param1=value1, param2=value ) It's all, I never call and writes/update in the auth_user anywhere. In gluon/tools.py login function, web2py check if they would use their login form or from a central source (line 1955) At line 2068 web2py determined that central authentication would be used. At line 2075 web2py call: user = self.get_or_create_user(table_user._filter_fields(cas_user)) At line 1724, within get_or_create_user function, after that web2py determine that the user exists: *update_keys = dict(registration_id=keys['registration_id']) #here is the BUG* I solved it with: *update_keys = dict(registration_id=keys['registration_id'], employee_id=keys['employee_id'])* So, I think that we need to update the gluon/tools.py file, to improve the update of external fields. On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote: On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote: I only return a dict in the get_user, web2py does all the work. web2py call the get_user method, and web2py update the auth_user table with the dict values. Yes, but where are you telling web2py to update the auth_user table? Can you show the code? Anthony On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote: Perhaps I misunderstand the workflow. The solution cannot be to change an Auth function to handle a specific custom field. The proper signature for the function is get_or_create_user(self, keys, update_fields=['email']) so if you want to pass employee_id to keys and expect it to update the record in case it is found you need to pass get_or_create_user
[web2py] web2py don't create or update tables and fields
I have a weird problem with web2py. It can't create or update tables in MySql. Although I'm using auth.define_tables(username=False, signature=False). I only need to refresh my web browser for changes take effect, right? What am I doing wrong? Thank you. --
[web2py] RuntimeError: Using a recursive select but encountered a broken reference: auth_group
I've an app, I register and user and it's ok. I have 1 instance running with python web2py.py at port 8080 (for admin console) ... and I have my httpd.conf configured with WSGI. Both work correctly, but when I try to login in the normal instance (at port 80), I get an error RuntimeError: Using a recursive select but encountered a broken reference: auth_group 1. If I try to do it at port 8080 all works good. --
[web2py] Re: error when logging in using site domain
I have the same problem, do you have resolved it? Thanks. On Wednesday, January 2, 2013 7:38:47 PM UTC-6, dr_eeves wrote: Hi, I have been developing a web application using web2py. Most of the development has been done using the included development text editor (which has been great to use!). I'm required to use https when using the Administrative interface through my hosting provider. I get around this for now by using an ssh tunnel that allows me to connect through local host on my computer. When I log into my site with this setup (ssh tunnel), I have no problems using the site. However, when I try to log in through my site's domain directly, I get the following error: RuntimeError: Using a recursive select but encountered a broken reference : auth_group 1 I am not sure what is different been the two access methods which would cause such an error. Does anyone have any idea how to fix this issue? Thanks, Darryl --
[web2py] Re: RuntimeError: Using a recursive select but encountered a broken reference: auth_group
Massimo, Thank you, I found the solution. I have wrong RewriteCond and RewriteRule parameters at httpd.conf I have a domain.com working with Apache, and I configured an alias /myapp that works to web2py framework. The good configuration for this case is. VirtualHost *:80 DocumentRoot /var/www/html ServerName www.domain.com ServerAlias domain.com *.domain.com Directory /var/www/html Options FollowSymLinks AllowOverride All /Directory *RewriteEngine On* *RewriteCond %{REQUEST_URI} ^/**myapp**.* [NC]* *RewriteRule ^/(.*) /myapp/$1 [PT,L]* *WSGIScriptAlias /**myapp** /opt/web2py/wsgihandler.py* /VirtualHost Best regards. On Friday, January 4, 2013 6:55:30 PM UTC-6, Massimo Di Pierro wrote: Looking into this... On Friday, 4 January 2013 15:53:05 UTC-6, Ignacio Ocampo wrote: I've an app, I register and user and it's ok. I have 1 instance running with python web2py.py at port 8080 (for admin console) ... and I have my httpd.conf configured with WSGI. Both work correctly, but when I try to login in the normal instance (at port 80), I get an error RuntimeError: Using a recursive select but encountered a broken reference: auth_group 1. If I try to do it at port 8080 all works good. --
[web2py] Re: error when logging in using site domain
Darry, I had the same problem, I post my solution at: http://nafiux.com/blog/2013/01/04/web2py-deploy-specific-app-with-apache-webserver/ In my case, the problem was caused by a bad RewriteRule configuration at my httpd.conf file. The correct configuration that I used is: VirtualHost *:80 DocumentRoot /var/www/html ServerName www.domain.com ServerAlias domain.com *.domain.com Directory /var/www/html Options FollowSymLinks AllowOverride All /Directory RewriteEngine On RewriteCond %{REQUEST_URI} ^/myapp.* [NC] RewriteRule ^/(.*) /myapp/$1 [PT,L] WSGIScriptAlias /myapp /opt/web2py/wsgihandler.py /VirtualHost Best regards. On Wednesday, January 2, 2013 7:38:47 PM UTC-6, dr_eeves wrote: Hi, I have been developing a web application using web2py. Most of the development has been done using the included development text editor (which has been great to use!). I'm required to use https when using the Administrative interface through my hosting provider. I get around this for now by using an ssh tunnel that allows me to connect through local host on my computer. When I log into my site with this setup (ssh tunnel), I have no problems using the site. However, when I try to log in through my site's domain directly, I get the following error: RuntimeError: Using a recursive select but encountered a broken reference : auth_group 1 I am not sure what is different been the two access methods which would cause such an error. Does anyone have any idea how to fix this issue? Thanks, Darryl --
[web2py] Facebook auth plugin (Basic HTTP Authentication code improvement)
Currently the function __build_url_opener is: def __build_url_opener(self, uri): Build the url opener for managing HTTP Basic Athentication # Create an OpenerDirector with support # for Basic HTTP Authentication... auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(None, uri, self.client_id, self.client_secret) opener = urllib2.build_opener(auth_handler) return opener The correct form based on python documentation (http://docs.python.org/2/library/urllib2.html#examples, Use of Basic HTTP Authentication) def __build_url_opener(self, uri): password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(realm=None, uri=uri, user=self.client_id, passwd=self.client_secret) handler = urllib2.HTTPBasicAuthHandler(password_mgr) opener = urllib2.build_opener(handler) return opener --