Using couchdbkit (3rd party library) on Google App Engine - python

I'm having difficulty getting couchdbkit to function properly on Google App Engine. I'm either not importing my libraries correctly or I've run afoul of GAE's Python Sandbox rules. Anyone know if I need to include restkit when using couchdbkit on GAE (that's where some of the problems are coming from)?
Here's my configuration:
app.yaml
zapdome.py
couchdbkit/
restkit/
I've stripped zapdome.py to just the basics (connect to my CouchDB database server):
#! /usr/bin/env python
import urllib, httplib, datetime
from couchdbkit.schema.base import *
from couchdbkit.schema.properties import *
from couchdbkit.client import Server
USERNAME = ''
PASSWORD = ''
class QuoteEntry(Document):
name = StringProperty()
symbol = StringProperty()
price = StringProperty()
server = Server('https://' + USERNAME + ':' + PASSWORD + '#' + USERNAME + '.cloudant.com/')
These are the errors I'm logging:
E 2011-05-05 20:39:31.309
Traceback (most recent call last):
E 2011-05-05 20:39:31.309
File "/base/data/home/apps/zapdome/1.350215157753999092/restkit/__init__.py", line 12, in <module>
E 2011-05-05 20:39:31.309
from .client import Client, MAX_FOLLOW_REDIRECTS
E 2011-05-05 20:39:31.309
File "/base/data/home/apps/zapdome/1.350215157753999092/restkit/client.py", line 21, in <module>
E 2011-05-05 20:39:31.309
from httplib import FakeSocket
E 2011-05-05 20:39:31.309
ImportError: cannot import name FakeSocket
E 2011-05-05 20:39:31.309
Traceback (most recent call last):
E 2011-05-05 20:39:31.309
File "/base/data/home/apps/zapdome/1.350215157753999092/couchdbkit/__init__.py", line 10, in <module>
E 2011-05-05 20:39:31.310
from .resource import RequestFailed, CouchdbResource
E 2011-05-05 20:39:31.310
File "/base/data/home/apps/zapdome/1.350215157753999092/couchdbkit/resource.py", line 25, in <module>
E 2011-05-05 20:39:31.310
from restkit import Resource, ClientResponse
E 2011-05-05 20:39:31.310
ImportError: cannot import name Resource
E 2011-05-05 20:39:31.310
<type 'exceptions.SyntaxError'>: 'import *' not allowed with 'from .' (__init__.py, line 159)
Traceback (most recent call last):
File "/base/data/home/apps/zapdome/1.350215157753999092/zapdome.py", line 4, in <module>
from couchdbkit.schema.base import *
Since it's choking on httplib.FakeSocket and restkit.Resource, I'm beginning to think I'm going outside the bounds of what GAE permits. Anyone have any thoughts? Thanks.

I hate to answer my own question, but it appears I was trying to do things outside the confines of GAE's Python Sandbox. I think it took issue with the socket stuff. The good folks at Cloudant pointed me to this Quora answer that lays out more liberal hosting options for Python/Django.
BTW, I went with WebFaction and got everything working fine within an hour and I'm definitely no sys admin (but they do not offer a free hosting solution).

In this instance, the problem looks to be import syntax rather than sandboxing rules. It's complaining because you're doing an import * from base, which then tries to import from .resource. Using import * with a relative module path is disallowed in Python 2.5.
You can try changing your import * to import only what you actually need, e.g. Document.

Related

AttributeError: module 'wsgi' has no attribute 'application'

app.py file code:
import webbrowser
import time
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import certifi
import json
def get_jsonparsed_data(url):
"""
Receive the content of ``url``, parse it as JSON and return the object.
Parameters
----------
url : str
Returns
-------
dict
"""
response = urlopen(url, cafile=certifi.where())
data = response.read().decode("utf-8")
return json.loads(data)
url = ("https://financialmodelingprep.com/api/v3/quote/AAPL,FB?apikey=d099f1f81bf9a62d0f16b90c3dc3f718")
print(get_jsonparsed_data(url))
country = get_jsonparsed_data(url)
count = 0
for result in country:
if count == 0:
header = result.keys()
for head in header:
html_content = f"<div> {head} </div>"
count += 1
with open("index.html", "w") as html_file:
html_file.write(html_content)
print("Html file created successfully !!")
time.sleep(2)
webbrowser.open_new_tab("index.html")
passenger_wsgi.py file code:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.application
Error:
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Hi,
Everyone, I am new in Python. I have develop a basic application on my local machine. But when I deployed it on A2Host hosting server. I am facing above error when I run my application in web browser.
Is anyone help me to fix above issue. I will be very thankful for that person.
I will applogize in advance for my brief answer. But it has to do with the fact that you have not established a whisky app.
You need to make sure in your main application file app.py you establish your application.
def app(environ, start_response):
pprint("whoo hooo. ")
I hope this helps.

Is it possible to import a python file from outside the directory the main file is in?

I have a file structure that looks like this:
Liquid
|
[Truncate]
|_General_parsing
[Truncate]
.....|_'__init__.py'
.....|_'Processer.py'
.....|'TOKENIZER.py'
|_'__init__.py'
|_'errors.py'
[Truncate]
I want to import errors.py from Processer.py. Is that possible? I tried to use this:
from ..errors import *; error_manager = errorMaster()
Which causes this:
Traceback (most recent call last):
File "/Users/MYNAME/projects/Liquid/General_parsing/Processer.py", line 17, in <module>
from ..errors import *; error_manager = errorMaster()
ImportError: attempted relative import with no known parent package
[Finished in 0.125s]
I've seen this post, but it's no help, even if it tries to solve the same ImportError. This isn't, either (at least not until I edited it), since I tried:
import sys
sys.path.insert(1, '../Liquid')
from errors import *; error_manager = errorMaster()
That gives
Traceback (most recent call last):
File "/Users/MYNAME/projects/Liquid/General_parsing/Processer.py", line 19, in <module>
from errors import *; error_manager = errorMaster()
ModuleNotFoundError: No module named 'errors'
[Finished in 0.162s]
EDIT: Nevermind! I solved it! I just need to add .. to sys.path! Or . if .. doesn't solve your problem. But if those don't solve your problem: use some pathlib (came in python3.4+) magic and do:
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).parent))
or, if you want to use os: (gotten from this StackOverflow answer)
import os
os.path.join(os.path.dirname(__file__), '..')
I solved it! I have to add .. to sys.path instead

In Python got many issues with Spyne

Well, here's my Python code:
#!/usr/bin/env python
from spyne import Application, rpc, ServiceBase, Unicode
from lxml import etree
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
# Wsgi это Web server Getewap Interface - стандар взаимодействия с питон программой и серверо где он работает
class Soap(ServiceBase):
#rpc(Unicode, _return=Unicode)
def Insoap(ctx, words):
print("Connection detected: ", etree.tostring(ctx.in_document))
ww = str(words).capitalize()
return ww
app = Application([Soap], tns='Capitalize', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
application = WsgiApplication(app) # Важна названия переменной, иначе сервер не поймет
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('localhost', 8002, application)
server.serve_forever()
But get this error, what's the problem? What should I do for a solution? Please, get help me to solve this problem
Traceback (most recent call last):
File "C:/Users/David374/PycharmProjects/untitled8/venv/test.py", line 3, in <module>
from spyne import Application, rpc, ServiceBase, Iterable, UnsignedInteger, \
File "C:\Users\David374\PycharmProjects\untitled8\venv\lib\site-packages\spyne\__init__.py", line 63, in <module>
from spyne.server import ServerBase, NullServer
File "C:\Users\David374\PycharmProjects\untitled8\venv\lib\site-packages\spyne\server\__init__.py", line 23, in <module>
from spyne.server.null import NullServer
File "C:\Users\David374\PycharmProjects\untitled8\venv\lib\site-packages\spyne\server\null.py", line 69
self.service = _FunctionProxy(self, self.app, async=False)
^
SyntaxError: invalid syntax
async is a reserved keyword in Python 3.7+, and you'll need to use the latest version of Spyne, which doesn't use that reserved keyword as a parameter in its functions, if you want to use it with Python 3.7+.
Either update Spyne to spyne-2.13.2-alpha, or use Python 3.6 or lower.
Sources:
https://docs.python.org/3/whatsnew/3.7.html
https://pypi.org/project/spyne/2.13.2a0/

Python 3.7 ImportError: cannot import name 'XXXX'

I'm starting with Python, and I'm developing a simple program.
But the interpreter shouts at me when I try to import a method in a separate file.
Here is my configuration:
file A.py (main):
import os
import copy
import locale
from C import some_function1, some_function2, some_function3
file B.py:
import os
from C import some_function
file C.py:
import os
import time
from B import some_class
from B import some_class
It does not work and I get the following error:
Traceback (most recent call last):
File "G:/XXXX/XXXX/A.py", line 5, in <module>
from C import some_function1, some_function2, some_function3
File "G:\XXXX/XXXX\C.py", line 3, in <module>
from B import some_class
File "G:\XXXX/XXXX\B.py", line 3, in <module>
from C import some_function
ImportError: cannot import name 'some_function4' from 'C' (G:\XXXX/XXXX\Fonctions.py)
But it works when in the B file I replace from C import some_function by import C and when I use C.some_function4 instead of just some_function4.
My program works well and I have at least one option that allows me to continue, but I would like to know what I'm doing wrong ...
I guess it's a self-inclusion problem as I already had in C ++ but I do not know python well enough to see how I could fix that.
Someone can help me with that?

ImportError: No module named 'requests.packages.urllib3.contrib.appengine'

I can't run my script I'm using python3 and I install pyrebase and his dependencies
I got this below exception when I try to run my script on linux ubuntu
Traceback (most recent call last):
File "scrapping2fb.py", line 9, in <module>
import pyrebase
File "/usr/local/lib/python3.4/dist-packages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/usr/local/lib/python3.4/dist-packages/pyrebase/pyrebase.py", line 19, in <module>
from requests.packages.urllib3.contrib.appengine import is_appengine_sandbox
Can some one help me
Thank you
The script that i try to run
from urllib.request import urlopen ,URLError,HTTPError,Request
from socket import timeout
from bs4 import BeautifulSoup
from time import sleep
import mysql.connector
from datetime import datetime
import pyrebase
def is_exist_firebase_db_AR(siteName,title):#(siteName,title):
global config
global email
global password
firebase = pyrebase.initialize_app(config)
db=firebase.database()
auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email, password)
all_items = db.child("items_ar").get(user['idToken'])
if(all_items.each() is not None):
for item in all_items.each():
if(siteName in item.val().get("nomSite") and title in item.val().get("titre")):
return 1
return 0
This is a problem with the pyrebase package.
Since commit 8e17600ef60de4faf632acb55d15cb3c178de9bb which went into v2.16.0, requests no longer bundle urllib3.
The package pyrebase is relying on this implementation detail, and, like all things that rely on implementation details eventually do, was broken.

Categories

Resources