Item in ``from list'' not a string (custom_import.py) web2py 2.9.11

331 views
Skip to first unread message

Luciano Laporta Podazza

unread,
Oct 11, 2014, 7:53:40 PM10/11/14
to web...@googlegroups.com
Hello,

I'm using locally web2py (2.9.8) + Shopify API (2.0.4) on Mac OS X 10.9.5 (Python 2.7.5) and this code works perfectly:

from gluon.tools import Service
service
= Service()
import gluon.contrib.simplejson as json


def call():
    session
.forget()
   
return service()


@service.json
def create_order():
    data
= json.loads(request.body.read())
   
import shopify
   
#(API Key, Password)
    shop_url
= "https://%s:%s...@myshop.myshopify.com/admin" % ('key','secret')
    shopify
.ShopifyResource.set_site(shop_url)
    shop  
= shopify.Shop.current
    orders
= shopify.Order.find(financial_status='pending')
    new_order
= shopify.Order()


   
for order in orders:
       
if order.order_number == data['order_number']:
            clone_order
(order, new_order, order.attributes)


def clone_order(objfrom, objto, names):
   
for n in names:
       
if hasattr(objfrom, n):
           
if n in ["source_name", "cart_token", "id", "token", "name", "checkout_token", "checkout_id"]:
                objto
.n = None
           
elif n == "line_items":
                v
= getattr(objfrom, n)
                setattr
(objto, n, v)
               
if objto.line_items[-1].title != "Cargo por COD":
                    objto
.line_items.append({"variant_id" : 972802884, "quantity" : 1, "price": 2.5, "title": "Cargo por COD"})
           
elif n == "order_number":
                v
= getattr(objfrom, n)
                objto
.note = "Agregado COD, numero de orden vieja: #" + str(objfrom.order_number)
           
else:
                v
= getattr(objfrom, n)
                setattr
(objto, n, v)
                objto
.order_number = 1198
   
try:
        objto
.save()
        objfrom
.cancel()
        objfrom
.close()
       
return "Success"
   
except Exception, e:
       
return "Fail"

But when deploying to server (Ubuntu 14.04 with Web2py 2.9.11 / Python 2.7.6 -note the different python and web2py version-) I get this error:

Traceback (most recent call last):
 
File "/home/www-data/web2py/gluon/restricted.py", line 224, in restricted
 
exec ccode in environment
 
File "/home/www-data/web2py/applications/mascotanube/controllers/cash_on_delivery.py", line 49, in <module>
 
File "/home/www-data/web2py/gluon/globals.py", line 392, in <lambda>
 
self._caller = lambda f: f()
 
File "/home/www-data/web2py/applications/mascotanube/controllers/cash_on_delivery.py", line 7, in call
 
return service()
 
File "/home/www-data/web2py/gluon/tools.py", line 5138, in __call__
 
return self.serve_json(request.args[1:])
 
File "/home/www-data/web2py/gluon/tools.py", line 4815, in serve_json
 s
= universal_caller(self.json_procedures[args[0]], *args[1:], **d)
 
File "/home/www-data/web2py/gluon/tools.py", line 4474, in universal_caller
 
return f(**arg_dict)
 
File "/home/www-data/web2py/applications/mascotanube/controllers/cash_on_delivery.py", line 17, in create_order
 orders
= shopify.Order.find(financial_status='pending')
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 385, in find
 
return cls._find_every(from_=from_, **kwargs)
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 524, in _find_every
 prefix_options
)
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 555, in _build_list
 resources
.append(cls(element, prefix_options))
 
File "build/bdist.linux-i686/egg/shopify/base.py", line 130, in __init__
 
return super(ShopifyResource, self).__init__(attributes, prefix_options)
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 362, in __init__
 
self._update(attributes)
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 952, in _update
 klass
= self._find_class_for(key)
 
File "/usr/local/lib/python2.7/dist-packages/pyactiveresource/activeresource.py", line 1016, in _find_class_for
 __import__
('.'.join([module.__name__, element_name]))
 
File "/home/www-data/web2py/gluon/custom_import.py", line 82, in custom_importer
 modules_prefix
, globals, locals, [itemname], level)
TypeError: Item in ``from list'' not a string

I also tested it with web2py 2.9.11 locally and it works fine too so I can't figure it out where the issue is.

Any help will be appreciated. Thanks.

Niphlod

unread,
Oct 12, 2014, 9:07:03 AM10/12/14
to web...@googlegroups.com
uhm, could be something related to

http://bugs.python.org/issue21720




On Sunday, October 12, 2014 1:53:40 AM UTC+2, Luciano Laporta Podazza wrote:
Hello,

I'm using locally web2py (2.9.8) + Shopify API (2.0.4) on Mac OS X 10.9.5 (Python 2.7.5) and this code works perfectly:

from gluon.tools import Service
service
= Service()
import gluon.contrib.simplejson as json


def call():
    session
.forget()
   
return service()


@service.json
def create_order():
    data
= json.loads(request.body.read())
   
import shopify
   
#(API Key, Password)

    shop_url
= "https://%s:%s@myshop.myshopify.com/admin" % ('key','secret')

Luciano Laporta Podazza

unread,
Oct 12, 2014, 1:39:16 PM10/12/14
to web...@googlegroups.com
It seems to.

I've tried using pyenv to switch to Python 2.7.5 (the one it works), declared it as global and verified that works running 'python', reinstalled web2py 2.9.11 on server but web2py it still uses Python 2.7.6.

On the other hand I've tried to apply the patch with no luck (actually I'm learning how to do it :P)

Any suggestions?. Thanks!

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/k5193zQX6kM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Atte
Luciano Laporta Podazza

Niphlod

unread,
Oct 13, 2014, 3:28:02 PM10/13/14
to web...@googlegroups.com
it's not a web2py issue but it seems something with the Shopify lib and that bug that isn't going very well.... as of "web2py starts with something else" you need to check your setup.... web2py can't choose what python version to run at runtime....

Luciano Laporta Podazza

unread,
Oct 13, 2014, 3:37:05 PM10/13/14
to web...@googlegroups.com
Thanks Niphlod,

I've just managed to make any python version work (< 2.7.5), web2py runs the Python version I want but the error still remains.

It's weird 'cause on my Mac, with Python 2.7.5 (default, Mar  9 2014, 22:15:05) it works like a charm.

I'll keep the research but this is driving me nuts.


Luciano Laporta Podazza

unread,
Oct 15, 2014, 6:18:30 PM10/15/14
to web...@googlegroups.com
Hi again,

So a friend of mine helped me solving the issue, on gluon/custom_import.py, on line 82 we have to replace this line:

modules_prefix, globals, locals, [itemname], level)

With this one:

modules_prefix, globals, locals, [itemname.encode('utf-8')], level)

And that's all!. 

Thanks for your support!
Reply all
Reply to author
Forward
0 new messages