Matt | 24 May 2013 02:35
Picon

BUG in JSON parsing in main.py

Hi there,

I'm using Version 2.4.6-stable+timestamp.2013.05.17.14.52.19, Running on mac, Python 2.7.2, no external JSON library installed.

Sending the following data via PUT, application/json; charset=UTF-8:

{"id": 3}

results in a JSON parser error occurring at main.py:

    if is_json:
        try:
            logging.info('before') <--- my addition
            json_vars = sj.load(body)
            logging.info('after') <--- my addition
            body.seek(0)
        except Exception, e: <--- my addition
            logging.exception(e) <--- my addition
            # incoherent request bodies can still be parsed "ad-hoc"
            json_vars = {}
            pass
        # update vars and get_vars with what was posted as json
        request.get_vars.update(json_vars)
        request.vars.update(json_vars)

INFO     2013-05-24 00:07:21,100 main.py:337] before
INFO     2013-05-24 00:07:21,100 main.py:338] <module 'json' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py'>
ERROR    2013-05-24 00:07:21,100 main.py:346] No JSON object could be decoded
Traceback (most recent call last):
  File "/Projects/www/app/gluon/main.py", line 340, in parse_get_post_vars
    json_vars = sj.load(body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 278, in load
    **kw)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")

Appears to be related to the id() function for some reason, as changing the attribute name to anything other than "id" works fine. 

Help on built-in function id in module __builtin__:

id(...)

    id(object) -> integer

    Return the identity of an object.  This is guaranteed to be unique among
    simultaneously existing objects.  (Hint: it's the object's memory
    address.)

If I explicitly force it to use contrib.simplejson. i.e. change the top of main.py

try:
    import simplejson as sj #external installed library
except:
    try:
        import contrib.simplejson as sj #pure python library <--- Pasted.
    except:
        import contrib.simplejson as sj #pure python library

I get the same result.

Any ideas?

Thanks in advance,
Matt

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
António Ramos | 24 May 2013 00:22
Picon
Gravatar

dynamic dal query

hello 
i have 4 functions to do the same query.
db(db.mytable1.id>0).select()
db(db.mytable2.id>0).select()
db(db.mytable3.id>0).select()
db(db.mytable4.id>0).select()

Maybe i can use only one like this


def f1(table_to_query):
    row=db(db[table_to_query].id>0).select()

it does not work


what is the correct syntax?


in console i can see that the next  code works
table_to_query='mytable'
print db[table_to_query].fields
output
['id','field1','field2',etc....]


--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Ian W. Scott | 23 May 2013 23:49
Picon
Gravatar

Append() multiple components to html helper

Is there a way to append multiple components to an HTML helper in a single append() call, or do we have to use a separate append() call for each component?

I'm trying to append four components to a SPAN helper held in the variable "wrapper." I've tried it this way:

wrapper.append(new_component_1, new_component_2, new_component_3, new_component_4)

But the append() function seems to want only one argument. The code above raises an error, saying that I've submitted too many arguments.

Thanks!

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Cliff Kachinske | 23 May 2013 23:21
Picon

Postgres users beware auth.signature is_active; bad problem, easy to fix

auth.signature appends a "boolean" field called is_active to a table.  The default is True.


Under the covers it's not really boolean, it's char(1).  When you insert a record, is_active is set to "t".  That's right, a lowercase t.

Today I had the kind of problem where queries were missing records.  It turns out that the DAL was emitting queries looking for 'T' in is_active.

The queries were missing records because Postgres is case sensitive in char fields.  

I don't really understand why the dal adapters for Postgres transmogrify boolean fields to char(1) when Postgres supports boolean fields.  The nice thing about that is Postgres boolean fields do not care about case.

The easy fix for this problem is make sure that any fields you have defined as boolean in your models are also boolean in Postgres.

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
samuel bonilla | 23 May 2013 21:35
Picon

monitoring your web app

for web2py.....

http://newrelic.com/lp/python-monitoring?utm_source=REMK&utm_medium=remarketing&utm_content=rpm&utm_campaign=RPM&utm_term=graph250&mpc=TA-REMK-RPM-EN-0-NewLP-textad&gclid=COWghpP7rLcCFYWf4AodWlQAAA

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
bracquet | 23 May 2013 20:51
Picon

Redirect to another controller function with arguments from a callback function?

In my views, I have:


{{=A('click for more information', _href=URL("myCallback", args=[1]))}}


When the anchor button is clicked, my callback will do some lookup and processing in the db, and then will redirect to a new page populated with the new information:

def search_results():
    resultSet
= request.args(0)
   
# Build HTML helpers using resultSet
    div
= DIV(.....)

   
return dict(div=div)

def myButton():
     
# Figure out the id from the request
     someId
= request.args(0)

     
# get some data from db using the id
     resultSet
= db(....)


     
# want to redirect to another page with the new data in the resultSet
    redirect
(URL('search_results', args=resultSet))

But doing the redirect with the resultSet args will screw up the URL and I'll end up with an invalid request. 

I've thought of two ways around this:

1) Create a temporary session variable and store the resultSet there. Once I'm done with the data, I'll explicitly clear it.

2) Instead of doing the database logic in the callback, pass the id to the search_results() and do the database logic there.

I'm hesitant to adopt the first option because it seems messy to create a bunch of session variables for temporary things (unless this is standard practice?).

The second option seems okay, but I'm afraid that the code will become too specific to that particular anchor tag. That is, if I create a new anchor tag to do some other search, the database logic may be different than the one inside the search_results(). For this, I guess the better question should be if the database logic code should live in the callback function or in the target redirect controller function?


In spite of this, what would be the clean or proper way of sending data with a redirect from a callback function?

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Nam Soo In | 23 May 2013 20:22
Picon

how to use library in web2py

I am trying to use library from http://grabz.it/api/python/

I put library in controller and module and import GrabzItClinet 
I basically copy the whole directory(GrabzIt) into controller and module 
The error says
Cannot import module 'GrabzItClient'

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
gthwang5 | 23 May 2013 05:31
Picon

third party modules installation

Hi, 


I am currently hosting my site that I'm developing from my Windows 8 machine. 

I have my python installed in my computer at c:\python27\ and all the libraries get installed to c:\python27\site-packages I believe.

According to the web2py doc, it says in order to use third party modules, I need to install the module again straight into my web2py/site-packages folder.

However, this seems impossible because easy-install just keeps installing to c:\python27\site-packages.

Is there a solution? Thanks

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Ahmad Faiyaz | 23 May 2013 10:44
Picon
Gravatar

How to force Auth module to disable Password encryption!

Hello,

I am new on web2py. I am using it to develop a Programming Contest Management system. Now on a ONSITE Programming Contest , we have to distribute username and password printed on paper. So i have implemented a function which will generate user accounts automatically then print the passwords on a PDF. Web2py uses encrpytion to store the password, which is not retrievable. Now i can have a different table to store the passwords, but when i use use Auth to modify the password, i will be unable to update my own table. What to do now ? How i can disable encryption on auth_user table ? Can anyone help !!

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
gthwang5 | 23 May 2013 05:55
Picon

Pandas installation

How do install Pandas on web2py?

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
gthwang5 | 23 May 2013 17:34
Picon

installing Pandas in site-packages


I am running into issues installing pandas (or any third-party module). 

Basically, my python on my windows machine sits on c:\python27\, and pandas is installed in c:\python27\Lib\Site-Packages\pandas

Now, when I try to include pandas in my web2py app, however, I am getting an error saying it can't import it. 

I am assuming that web2py does not use my local python but its own. 

How do I get around this issue and either a) have web2py use my local python interpreter and its modules  or b) install python directly
to my web2py app's module's folder?   This is a noob question, sorry, but on windows or any environment I am not sure how to 
do a installation that's not to the python PATH and in some custom location.

Thanks,

--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gmane