Python: Where does import come from? - python-2.7

I have had this strange problem with import in python 2.7
I have my app in a directory that has some subdirectoriers and more python apps running simultaneously using Pyro Name Server for communicating with each other.
When I run one of my apps, it crashes on import when calling one of sub methods.
Here is the exception:
Traceback (most recent call last):
File "ps_logic.py", line 15840, in <module>
ps_logic = PSLogic(pyro_objects, cfg_handler, status_distributor, voip_processing)
File "ps_logic.py", line 590, in __init__
self.smarthopper_initial_check()
File "ps_logic.py", line 12824, in smarthopper_initial_check
counters_compared = self.smarthopper_maintenance_action()
File "ps_logic.py", line 12928, in smarthopper_maintenance_action
status = self.smart_hopper_logic.status_get()
File "/home/app_core/flexcore/003-480/ps_logic/smart_devices_logic.py", line 203, in status_get
return SmartStatusAugmented(self.smart_obj.queue_status_get(), self.smart_obj)
File "/usr/lib/python2.7/site-packages/Pyro/core.py", line 381, in __call__
return self.__send(self.__name, args, kwargs)
File "/usr/lib/python2.7/site-packages/Pyro/core.py", line 456, in _invokePYRO
return self.adapter.remoteInvocation(name, Pyro.constants.RIF_VarargsAndKeywords, vargs, kargs)
File "/usr/lib/python2.7/site-packages/Pyro/protocol.py", line 497, in remoteInvocation
return self._remoteInvocation(method, flags, *args)
File "/usr/lib/python2.7/site-packages/Pyro/protocol.py", line 536, in _remoteInvocation
answer = pickle.loads(answer)
ImportError: No module named drivers.smart.smart_common_const
it clearly says that it cannot import drivers.smart.smart_common_const BUT the problem is, I do not have that line in my code.
If I try to find in which file that line is (cuz I have already fixed it in some), it finds me nothing:
app_core#003-481 ~/flexcore/003-480 $ grep -R "from drivers.smart.smart_common_const import" .
./drivers/.svn/pristine/23/23e13acbf9e604f179d4625e18b2b992116a98a1.svn-base:from drivers.smart.smart_common_const import *
./drivers/.svn/pristine/65/65655973d3c70a16cc982db59db8f2989366524b.svn-base:from drivers.smart.smart_common_const import *
./drivers/.svn/pristine/3b/3ba2e2518e64db9188b63247b763926544bddd90.svn-base:from drivers.smart.smart_common_const import *
app_core#003-481 ~/flexcore/003-480 $
but svn files.
I have been running my python app with -v option to find out where it is trying to import from that file. BUT it is not returning nay debug line before that exception, so I guess its something imported previously or showing nothing if import fails.
I have also deleted all *.pyc files and rebooted machine to be sure there is noting left in memory, but problem persisted.
Is there any other option how to find out where is the problem? I am starting to be desperate..

That PS_Logic (whatever it may be) seems to be using Pyro to do remote calls to a server. In particular the line with the following, seems to be a remote call:
self.smart_obj.queue_status_get()
The server sends back a custom object and because it uses pickle as serialization format , your client program tries to reconstruct that object. Apparently you don't have the correct modules available in your client code, because it is pickle that fails when it tries to import the required module for you (to reassemble the response into objects)
There's got to be something in the manual of that ps_logic module that tells you about how to use it correctly, and that you should have it installed in the client as well perhaps.
(It is advised to not use pickle by the way, and stick to Pyro's default serializer, but that's another story)

Related

I am getting a module not found error for authlib, I had followed the instructions as written

ModuleNotFoundError
ModuleNotFoundError: No module named 'authlib'
Traceback (most recent call last)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 184, in
find_app_by_string
app = call_factory(script_info, attr, args)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 119, in call_factory
return app_factory()
File "/app/superset/app.py", line 44, in create_app
raise ex
File "/app/superset/app.py", line 37, in create_app
app_initializer.init_app()
File "/app/superset/initialization/__init__.py", line 616, in init_app
self.init_app_in_ctx()
File "/app/superset/initialization/__init__.py", line 564, in init_app_in_ctx
File "/app/superset/initialization/__init__.py", line 656, in configure_fab
appbuilder.init_app(self.superset_app, db.session)
File "/usr/local/lib/python3.8/site-packages/flask_appbuilder/base.py", line 202, in
init_app
self.sm = self.security_manager_class(self)
File "/usr/local/lib/python3.8/site-
packages/flask_appbuilder/security/sqla/manager.py",
line 54, in __init__
super(SecurityManager, self).__init__(appbuilder)
File "/usr/local/lib/python3.8/site-packages/flask_appbuilder/security/manager.py",
line 263, in __init__
from authlib.integrations.flask_client import OAuth
ModuleNotFoundError: No module named 'authlib'
The debugger caught an exception in your WSGI application. You can now look at the
traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on
the "Traceback" headline. From the text traceback you can also create a paste of it.
For code execution mouse-over the frame you want to debug and click on the console
icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra
helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
This is my directory structure: /home/directory/superset/superset-frontend.
I'm runnning superset in docker and I'm trying to get OAuth working.
I’ve edited the config file and added the OAuth configuration.
One of the lines I added was:
AUTH_TYPE = AUTH_OAUTH
This required me to import the auth types as below:
from flask_appbuilder.security.manager import (
AUTH_OID,
AUTH_REMOTE_USER,
AUTH_DB,
AUTH_LDAP,
AUTH_OAUTH,
)
When I try running npm run dev-server in development mode in superset.
I get the following error:
ModuleNotFoundError
ModuleNotFoundError: No module named 'authlib'

PyMongo 3 and ServerSelectionTimeoutError while getting data from Mongodb

This seems like an old solved problem here and here and here but Still I am getting this error.I create my db on Docker.And It worked only one time.Before this, I re-created db, did "connect =false",added wait, downgraded pymongo, did previous solutions etc. I stuck.
Python 3.8.0, Pymongo 3.9.0
from pymongo import MongoClient
import pprint
client = MongoClient('mongodb://192.168.1.100:27017/',
username='admin',
password='psw',
authSource='myappdb',
authMechanism='SCRAM-SHA-1',
connect=False)
db = client['myappdb']
serverStatusResult=db.command("serverStatus")
pprint(serverStatusResult)
and I am getting ServerSelectionTimeoutError
Traceback (most recent call last):
File "C:\Users\ME\eclipse2019-workspace\exdjango\exdjango__init__.py",
line 12, in
serverStatusResult=db.command("serverStatus")
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\database.py",
line 610, in command
with self.client._socket_for_reads(
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py",
line 113, in __enter
return next(self.gen)
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py",
line 1099, in _socket_for_reads
server = topology.select_server(read_preference)
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 222, in select_server
return random.choice(self.select_servers(selector,
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 182, in select_servers
server_descriptions = self._select_servers_loop(
File "C:\Users\ME\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py",
line 198, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: 192.168.1.100:27017: timed out
Your connection looks a little misconfigured. Firstly you have half connection string, half parameter format. I'd suggest you stick with one or the other.
Your auth database is usually seperate to your actual databases (and it's usually called admin). Check this is correct.
There's no particular need to specify the authMechanism assuming you are using MongoDB 3.0 or later.
The connect=False is likely a red herring.
So I would try one of either:
client = MongoClient('mongodb://admin:psw#192.168.1.100:27017/myappdb?authSource=admin')
or
client = MongoClient(host='192.168.1.100',
port=27017,
username='admin',
password='psw',
authSource='admin')

ImportError: cannot import name url

I'm upgrading a django app from v1.3 to 1.11.18.
We are running Python v2.7.12 and running an nginx server to serve the pages.
I've been making code changes to account for all of the deprecated methods as a result of the upgrade. So far, so good. After making another run of updates, I ran into this error notice after starting the server:
File "/home/bat/application.com/wsgi.py", line 12, in <module>
application = get_wsgi_application()
File "./django/core/wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "./django/core/handlers/wsgi.py", line 151, in __init__
self.load_middleware()
File "./django/core/handlers/base.py", line 56, in load_middleware
mw_class = import_string(middleware_path)
File "./django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "./django/middleware/locale.py", line 4, in <module>
from django.conf.urls.i18n import is_language_prefix_patterns_used
File "./django/conf/urls/i18n.py", line 2, in <module>
from django.conf.urls import url
ImportError: cannot import name url
I'm not sure why I would be getting this error as the code referenced is all core code. It doesn't appear to be referencing any of the project code at all, except for the opening line.
I've double-checked to be sure we do not have any "left over" code sitting in the core django folder: it's clean. We also rebooted the linux server just for kicks: that didn't help either. Beyond that I'm not really sure what else to try?
Any ideas where I might look for a solution to this one?
So it turns out that the ./django/conf/urls/__init__.py file is actually MISSING the required def url() function. I'm not sure how that didn't get noticed before by anyone, as the core code clearly calls that url function all over the place.
To resolve that issue, I downloaded Django v1.10.x and copied the def url(...) function from the v1.10.x code into the django/conf/urls/__init__.py file and everything worked as expected.
I do realize that I modified a core file, but I wasn't sure how to get around the issue otherwise. This 1.x branch of Django is not under active development, so I figure that's probably okay.

Message: 'geckodriver' executable needs to be in PATH, but it already is?

I am writing a script that will save the complete contents of a web page. If I try using urllib2 and bs4 it only writes the contents of the logon page and none of the content after navigating to a search within the page. However, if I do a ctrl + s on the search results page, an html file is saved to disk that when opened in a text editor has all of the contents from the search results.
I've read several posts here on the subject and am trying to use the steps in this one:
How to save "complete webpage" not just basic html using Python
However, after installing geckodriver and setting the sys path variable I continue to get errors. Here is my limited code:
from selenium import webdriver
>>> from selenium.webdriver.common.action_chains import ActionChains
>>> from selenium.webdriver.common.keys import Keys
>>> br = webdriver.Firefox()
Here is the error:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
And here is where I set the sys path variable:
I've restarted after setting sys path variable.
UPDATE:
I am now trying to use the chromdriver as this seemed more straight forward. I downloaded hromedriver_win32.zip II'm on a windows laptop) from chromedriver's download page, set the environmetal variable path to:
C:\Python27\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe
but am getting the similar following error:
>>> br = webdriver.Chrome()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You have also to add the path of Firefox to the system variables manually,
you maybe have installed firefox some other location while Selenium is trying to find firefox and launch from default location but it couldn't find. You need to provide explicitly firefox installed binary location:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)
browser = webdriver.Firefox()

ImportError: No module named phonenumbers in Odoo (OpenERP v8)

I'm trying to intall the asterisk_click2dial module on ODOO and this error comes to me in the log file:
ValueError: Routing: posting a message without model should be with a parent_id (private mesage).
2015-03-09 15:23:38,262 11093 ERROR ? werkzeug: Error on request:
Traceback (most recent call last):
File "/home/odoo/odoo/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/home/odoo/odoo/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/opt/odoo/openerp/service/server.py", line 281, in app
return self.app(e, s)
File "/opt/odoo/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "/opt/odoo/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "/opt/odoo/openerp/http.py", line 1274, in __call__
self.load_addons()
File "/opt/odoo/openerp/http.py", line 1293, in load_addons
m = __import__('openerp.addons.' + module)
File "/opt/odoo/openerp/modules/module.py", line 79, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/opt/odoo/addons/base_phone/__init__.py", line 23, in <module>
from . import wizard
File "/opt/odoo/addons/base_phone/wizard/__init__.py", line 23, in <module>
from . import number_not_found
File "/opt/odoo/addons/base_phone/wizard/number_not_found.py", line 25, in <module>
import phonenumbers
ImportError: No module named phonenumbers
The problem is just that I installed that module (phonenumbers) plus the py-Asterisk module without errors using pip install phonenumbers and pip install py-Asterisk and the error persists.
I noticed I have at least two versions of python installed (2.6 and 2.7) but both modules are installed at the same version from odoo (I can see the modules in the python2.7 cli when, for example, I write phonenumbers or search).
Has anybody any idea what is happening to me? I'd be gratefull for some specific response. Thanks.
Here the connector's page: OpenERP - Asterisk connector
Ok, my bad. During odoo instalation I created a virtual environment under the Odoo system user account which was used solely by the Odoo server so I just need to install these modules under that enviorment. This works for me:
First let’s switch from root to the odoo user, then create a new virtual environment called odoo and activate it:
su - odoo
/usr/local/bin/virtualenv --python=/usr/local/bin/python2.7 odoo
source odoo/bin/activate
(If you have the virtual environment created like me just ignore the second line). Before starting the module installation we need to add the path to the PostgreSQL binaries, otherwise the PsycoPG2 module install will fail (I ignored this one too):
export PATH=/usr/pgsql-9.3/bin:$PATH
Then I can do pip install... Thank you all for your help.