python does not recognise firebase - python

i am recently learning python so this is my code
import firebase
firebase = firebase.FirebaseApplication("https://cleandzapp.firebaseio.com/")
data ={
'Name': 'nana',
'Email':'ghjjkk',
}
result = firebase.post('cleandzapp/student',data)
print(result)
and this is the error i got
C:\Users\Marc\PycharmProjects\pythonProject\venv\Scripts\python.exe "C:\Data\nana\studY\CS\2CS\S2\arduino\mini projet\CleanDzApp\firebase_test.py"
Traceback (most recent call last):
File "C:\Data\nana\studY\CS\2CS\S2\arduino\mini projet\CleanDzApp\firebase_test.py", line 1, in <module>
import firebase
File "C:\Users\Marc\PycharmProjects\pythonProject\venv\lib\site-packages\firebase\__init__.py", line 19, in <module>
from sseclient import SSEClient
ModuleNotFoundError: No module named 'sseclient'
Process finished with exit code 1

the initial problem has that solution ___>the async became a key word in the latest versions of pip so you should change the file async in this path C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\firebase into something else like nasync , also change the ---- from sync import process pool---- in init.py and firebase.py (in the same path) into to ---- from nsync import process pool---- , that should solve the problem

Related

ModuleNotFoundError: No module named 'pdf2docsx'

I have tried to write a sample code that converts the contents of pdf to word
this is the code :
from pdf2docsx import converter
pdf = 'main.pdf'
word = 'my.docx'
cv = converter(pdf)
cv.convert(word,start=0,end=None)
cv.close()
Although i already installed the module pdf2docx , it still doesn't exist
Traceback (most recent call last):
File "c:\Users\dell\Desktop\New folder (8)\My_Start\python\PdfToWord.py", line 2, in <module>
from pdf2docsx import converter
ModuleNotFoundError: No module named 'pdf2docsx'
The module appears to be called pdf2docx, whereas you have added an "s" to make pdf2docsx
https://pypi.org/project/pdf2docx/
Change your import to
from pdf2docx import converter
There's not supposed to be an "s" there

Importing a function from a sibling folder in python producing strange errors

I'm have a script 'zigbot.py' which was working, but I'm restructuring to dockerize and now I'm questioning my ability to code at all. What I'm trying to do is have a telegram-bot container, and a 'web' container (FLASK), and a nginx container.
Next to zigbot.py I have a folder - 'bot', which has many of my scripts and functions in. Upon trying from bot.somescript import a_function I am getting error after error.
Project structure
zigbot
bot
bot
__init__.py
conversations.py
ct.py
Docerfile
funcs.py
pricedata.py
requirements.txt
util.py
zigbot.py
nginx
somestuff
web
app
migrations
templates
__init__.py
config.py
forms.py
functions.py
models.py
routes.py
signals.py
__init__.py
Dockerfile
requirements.txt
zigweb.py
When running the code below, I get a whole range of strange errors - the one listed below shows ImportError - it can't find 'onboard' in funcs, but its definitely there. Before the restructure, this was working. If I comment out 'onboard' it errors on every function in the list.
from bot.conversations import key_conversation
from bot.crypto_functions import satoshi_to_btc
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
onboarded_message, blank_signal_message, send_signal_format, get_or_create_user, signal_detected_keyboard, log_me
Traceback (most recent call last):
File "zigbot.py", line 15, in <module>
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
File "ZigBot\bot\bot\funcs.py", line 2, in <module>
from zigbot.web.app import db, app
File "ZigBot\bot\zigbot.py", line 15, in <module>
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
ImportError: cannot import name 'onboard'
So I tried adding a .bot.conversation for (relative?) import, but this produces an even weirder error. I've included the code, the error, then the function I'm trying to import below:
from .bot.conversations import key_conversation
from .bot.crypto_functions import satoshi_to_btc
from .bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
onboarded_message, blank_signal_message, send_signal_format, get_or_create_user, signal_detected_keyboard, log_me
from ..web.app import db
from ..web.app.models import User, Signal
Traceback (most recent call last):
File "zigbot.py", line 13, in <module>
from .bot.conversations import key_conversation
ModuleNotFoundError: No module named '__main__.bot'; '__main__' is not a package
conversations.py
# Initialise conversationHandler states
def key_conversation(cancel):
# Define keyboards
keyboard = [
[InlineKeyboardButton('Previous', callback_data='onboard:key'),
InlineKeyboardButton('Next', callback_data='onboard:alldone')]]
conversation_keyboard = InlineKeyboardMarkup(keyboard)
Finally, I think I'm getting closer to the problem, I go back to the way I think it's supposed to be imported. From bot.funcs import x,y,y... I look in funcs.py and this is how its importing some other code from my Flask web app, but it doesn't like it.
funcs.py
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from web.app import db, app
from web.app.models import User
Traceback (most recent call last):
File "zigbot.py", line 15, in <module>
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
File "ZigBot\bot\bot\funcs.py", line 2, in <module>
from web.app import db, app
ModuleNotFoundError: No module named 'web'
So I change the import to go up a level since web is two levels above bot - which contains the script I'm importing to. So zigbot>bot>bot>funcs.py trying to import from zigbot>web>app>
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from ..web.app import db, app
from ..web.app.models import User
import telegram
Traceback (most recent call last):
File "zigbot.py", line 15, in <module>
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
File "\ZigBot\bot\bot\funcs.py", line 2, in <module>
from ..web.app import db, app
ValueError: attempted relative import beyond top-level package
This obviously doesn't work either. Given my structure of having bot and web how do I get this to work? I even tried pulling the scripts out of the second 'bot' folder but I get the same issues. Finally, my weirdest error which might provide a clue to what I'm doing wrong, if I change the import on funcs.py to go one level up, rather than two, I get an even stranger traceback.
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from .web.app import db, app
from .web.app.models import User
import telegram
Traceback (most recent call last):
File "zigbot.py", line 15, in <module>
from bot.funcs import onboard, main_menu, new_message1, new_keyboard, onboarded_keyboard, \
File "C:\Users\phill\PycharmProjects\ZigBot\bot\bot\funcs.py", line 2, in <module>
from .web.app import db, app
ModuleNotFoundError: No module named 'bot.web'
For clarity I removed some 'C:\Users\phill' from the tracebacks before realising it was pointless to remove that.
I think there's a fundamental flaw in your split if you have library dependencies across the boundary. Assuming that there are no imports of bot-modules in your web container, I would suggest breaking off the shared code into a module named weblib or something (alongside the bot-, nginx- and web-folders).
You still should not try to import across would-be container boundaries however, so just make sure weblib is in your path or installed in your virtual environment or however you want to handle it. Basically, bot and web should run in separate environments and should have weblib as a dependency.
Someone wiser than me might be able to explain it better.
For relative imports to work all the packages and subpackages must be in the sys.path - to achieve this you should run from the top-level directory as in:
C:\Users\phill\zigbot>python -m bot.zigbot
This will make your current working dir (zigbot) available to sys.path and the subpackages will be resolved correctly

Chatter Bot Corpus'Trainer' missing error

I'm attempting to start working with building chat bot within python. I would really want to start programming one from scratch. I'm starting with the ChatterBot module to learn how it works. I have pip installed all modules but I'm still having trouble with 'ChatterBotCorpusTrainer'Im getting a missing error. I run python 3.7 and I have the updated ChatBot module.
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os
bot= ChatBot('Bot')
trainer = ChatterBotCorpusTrainer(bot)
corpus_path = '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/chatterbot_corpus/data/english'
for file in os.listdir(corpus_path):
trainer.train(corpus_path + file)
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')
response = chatbot.get_response("Good morning!")
print(response)
this is the error I'm getting
/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/storage/jsonfile.py:26: UnsuitableForProductionWarning: The JsonFileStorageAdapter is not recommended for production environments.
self.UnsuitableForProductionWarning
Traceback (most recent call last):
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/chat_1_1.py", line 6, in <module>
trainer = ChatterBotCorpusTrainer(bot)
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/trainers.py", line 101, in __init__
from .corpus import Corpus
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/corpus/__init__.py", line 6, in <module>
from chatterbot_corpus import Corpus
ImportError: cannot import name 'Corpus' from 'chatterbot_corpus' (/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot_corpus/__init__.py)
You need to specify the module (chatterbot.trainers). You have 2 options:
1
from chatterbot import trainers
2
trainer = chatterbot.trainers.ChatterBotCorpusTrainer

PyCharm & console don't let me use local modules

I'm absolutely frustraded about the fact that I can't start my Python journey. I have a simple service which I use as a training with Python which is new for me.
I've downloaded PyCharm and as long as I had one file, everything was fine.
That I decided to to some structure and suddenly my project stopped working.
I have a structure like:
project/
project/employees
project/employees/__init__.py
project/employees/employees.py
project/server.py
project/venv/
project/venv/(...)
The project is a source root.
And yet I have something like this:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/project/server.py", line 5, in <module>
from employees.employees import Employees, EmployeesName
File "C:\Users\user\PycharmProjects\project\employees\employees.py", line 4, in <module>
from server import db_connect
File "C:\Users\user\PycharmProjects\project\server.py", line 5, in <module>
from employees.employees import Employees, EmployeesName
ImportError: cannot import name 'Employees'
I tested this with VS Code and CMD and the same happend.
I would be grateful for any suggestions!
EDIT:
employees.py:
from flask_jsonpify import jsonify
from flask_restful import Resource
from server import db_connect
class Employees(Resource):
(...)
class EmployeesName(Resource):
(...)
The problem here is that you have a circular dependency.
In employees.py you import server.py; and vice versa.
You have to rearrange your .py files in order that not to happen anymore.

No module named v4.proto.omni

I have installed pysnmp-4.x.I am getting following error during running a SNMP program.
I am using pysnmpSE 3.5.2 now but getting same error. I found that pysnmpSE doesn't hav v4 module. I was suggested that following error should resolved if pySNMP SE 3.x is used.
Traceback (most recent call last):
File "C:\Documents and Settings\ggne0622\Desktop\Python\google-python-exercises\babynames\SimpleAgent.py", line 18, in <module>
from twistedsnmp import agent, agentprotocol, bisectoidstore
File "C:\Python27\Lib\site-packages\twistedsnmp\agent.py", line 4, in <module>
from twistedsnmp import datatypes
File "C:\Python27\Lib\site-packages\twistedsnmp\datatypes.py", line 7, in <module>
from twistedsnmp.pysnmpproto import v2c,v1
File "C:\Python27\Lib\site-packages\twistedsnmp\pysnmpproto.py", line 13, in <module>
from pysnmp.v4.proto.omni import v2c,v1, error, rfc1157, rfc1905
ImportError: No module named v4.proto.omni
Code:
#!/usr/bin/env python
from twisted.internet.iocpreactor import reactor
from twisted.internet import error as twisted_error
from twistedsnmp import agent, agentprotocol, bisectoidstore
#from twisted.internet import interfaces
try:
from twistedsnmp import bsdoidstore
except ImportError:
import warnings
warnings.warn( """No BSDDB OID Storage available for testing""" )
bsdoidstore = None
def createAgent( oids ):
ports = [161]+range(20000,25000)
for port in ports:
try:
`agentObject = reactor.IOCPReactor.listenUDP(port,` `agentprotocol.AgentProtocol(snmpVersion = 'v2c',agent = agent.Agent(dataStore =` `bisectoidstore.BisectOIDStore(OIDs = oids,),),),)`
`except twisted_error.CannotListenError:`
`pass`
`else:`
`return agentObject, port`
testingOIDs = {
'.1.3.6.1.2.1.1.1.0': 'Some tool out in the field',
'.1.3.6.1.2.1.1.2.0': '.1.3.6.1.4.1.88.3.1',
'.1.3.6.1.2.1.1.3.0': 558566090,
'.1.3.6.1.2.1.1.4.0': "support#somewhere.ca",
'.1.3.6.1.2.1.1.5.0': "NameOfSystem",
'.1.3.6.1.2.1.1.6.0': "SomeHeadEnd, West Hinterlands, Canada",
}
def main(oids=testingOIDs):
agent, port = createAgent( oids )
if __name__ == "__main__":
reactor.IOCPReactor.callWhenRunning( main )
reactor.IOCPReactor.run()
TwistedSNMP does not seem to be designed to work with PySNMP 4.x. Thus you should either use PySNMP 3.x / PySNMP SE or switch to PySNMP 4.x which has its own Twisted binding.

Categories