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/
Related
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.
I'm trying to use IBM watson for sentiment analysis. but it is crashing on the import: from ibm_watson import NaturalLanguageUnderstandingV1
The whole code snippet is
import json
import constants from ibm_watson import NaturalLanguageUnderstandingV1 from ibm_cloud_sdk_core.authenticators
import IAMAuthenticator from ibm_watson.natural_language_understanding_v1 import Features, SentimentOptions
class SentimentAnalysis:
def __init__(self):
authenticator = IAMAuthenticator(constants.IBM_WATSON_KEY)
this.natural_language_understanding = NaturalLanguageUnderstandingV1(
version='2020-08-01',
authenticator=authenticator
)
this.natural_language_understanding.set_service_url(constants.IBM_WATSON_URL)
def analyse_sentiments(self, data):
response = this.natural_language_understanding.analyze(
text=data,
features=Features(sentiment=SentimentOptions())).get_result()
assert isinstance(response, object)
return response
My python version is Python 2.7.16
Installed IBM watson using pip install --upgrade "ibm-watson>=4.6.0"
The error I'm seeing is
/usr/bin/python /Users/rabbal1892/Desktop/DeepInsight/nextcontent-etl/scrapers/sentiment_analysis.py Traceback (most recent call last): File "/Users/rabbal1892/Desktop/DeepInsight/nextcontent-etl/scrapers/sentiment_analysis.py", line 3, in <module>
from ibm_watson import NaturalLanguageUnderstandingV1 File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_watson/__init__.py", line 16, in <module>
from ibm_cloud_sdk_core import IAMTokenManager, DetailedResponse, BaseService, ApiException File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_cloud_sdk_core/__init__.py", line 34, in <module>
from .base_service import BaseService File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_cloud_sdk_core/base_service.py", line 68
service_url: str = None,
^ SyntaxError: invalid syntax
I'll appreciate any help. Thanks.
The ibm-watson project description page mentions it's only tested on Python V3.x versions.
There is a lot of Python v3 syntax that is not compatible with Python v2.
Since you mention you have Python v2, you should Python v3 instead if you want to using the ibm-watson library as is, you will have to use Python v3.
Python unable to import package, but works correctly from within the package. A fully functional example below. In the virtual env I am using 3.6 All responses greatly appreciated!
parsers/
__init__.py
element.py
parser1.py
parser2.py
parserresolver.py
outsidepkg.py
init.py is empty
element.py:
def router():
pass
parser1.py:
from element import *
def parse(data):
return data
parser2.py:
from element import *
def parse(data):
return data
parserresolver.py:
import sys
from parser1 import *
from parser2 import *
def resolve(data):
parseddata = None
parsers = ['parser1', 'parser2']
funcname = 'parse'
for parser in parsers:
module = sys.modules[parser]
if hasattr(module, funcname):
func = getattr(module, funcname)
parseddata = func(data)
print(parseddata)
return parseddata
if __name__ == "__main__":
resolve('something')
outsidepkg.py:
import parsers.parserresolver
def getapi(data):
parsers.parserresolver.resolve(data)
if __name__ == "__main__":
print(getapi('in parse api main'))
So when I call parserresolver.py directly it works great, no import errors and prints out "something" as expected.
But when I call outsidepkg.py I am getting this error:
Traceback (most recent call last):
File "C:\code\TestImport\TestImport\outsidepkg.py", line 1, in <module>
import parsers.parserresolver
File "C:\code\TestImport\TestImport\parsers\parserresolver.py", line 2, in <module>
from parser1 import *
ModuleNotFoundError: No module named 'parser1'
Press any key to continue . . .
You need to change the imports of:
from file import whatever
To:
from .file import whatever
Since your code to run it is outside the folder, use a . to get the directory, since the file isn't outside the package.
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.
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.