I am using the following code to sign in to twitter:
import simplejson
import twitter
import oauth
import oauthtwitter
from oauthtwitter import OAuthApi
class OauthRequest():
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
AUTHORIZATION_URL = 'http://twitter.com/oauth/authorize'
REQUEST_TOKEN_URL = 'https://twitter.com/oauth/request_token'
def GetRequest(self):
vOauthApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET)
self.mOauthRequestToken = vOauthApi.getRequestToken(self.REQUEST_TOKEN_URL)
self.mOauthRequestUrl = vOauthApi.getAuthorizationURL(self.mOauthRequestToken)
However, I receive the following error message:
Traceback (most recent call last):
File "C:\Python33\twitter.py", line 4, in <module>
import oauthtwitter
File "C:\Python33\lib\site-packages\oauthtwitter.py", line 17, in <module>
from twitter import Api, User
ImportError: cannot import name Api
I have installed PIP and downloaded the 'oauth', 'oauthtwitter' and 'twitter' modules using it. I am running Windows Vista and Python 3.3. As far as I can tell in my 'Lib' folder the files are there for oauthtwitter.
I'm noy sure exactly what is going wrong here?
Thanks
Related
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
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
The below code throws the following error:
Traceback (most recent call last):
File "./python_PAN_traffic_scraper.py", line 4, in <module>
import urllib3
File "/usr/lib/python2.7/site-packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 29, in <module>
from ssl import CertificateError
ImportError: cannot import name CertificateError
What am I doing wrong? I want to browse to the firewall portal interface which uses a self-signed certfificate and throws a certificate error when attempting to browse to the site using a specific API URL and API key. Ultimately, I want to expand the code to parse through the XML to look for specific tags and attributes (source / destination / ports / etc).
#!/usr/bin/env python
import ssl
import urllib
import urllib3
import xml.etree.ElementTree as ET
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
DAL = "1.1.1.1"
CHI = "2.2.2.2"
firewall_ip = [ 'Dallas', 'Chicago' ]
datacenter=raw_input('Which firewall do you want traffic logs for? \"DAL\" or \"CHI\"?: ')
contents = ""
cmd = "/api/?type=log&log-type=traffic&query=(receive_time geq '2017/1/22 23:00:00')"
key = "&key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa="
url = "https://"+pan_ip[0]+urllib3.urlencode(cmd)+key
response = urllib3.urlopen(url, verify=False)
contents = ET.fromstring(response.read())
if DC is "DAL":
print contents
else:
print "Goodbye"
#result = ""
#for i in contents[0][0]:
# if i[0][0].tag == entry:
# for j in i[0][0]:
# if j.tag == 'src' and j.text == src:
# result = i.attrib['name']
#print result
I uninstalled urllib3 and did a fresh install:
$ git clone git://github.com/shazow/urllib3.git
cd to the folder containing urllib3/
$ python setup.py install
This got rid of the error completely.
I am trying to make an API call through Python to Google's DFA and am using their suggested code. However, it is still not saying the credentials object is defined and throws the error:
Traceback (most recent call last):
File "<input>", line 2, in <module>
File "C:\Python27\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Python27\lib\site-packages\oauth2client\client.py", line 1502, in __init__
_RequireCryptoOrDie()
File "C:\Python27\lib\site-packages\oauth2client\client.py", line 1456, in _RequireCryptoOrDie
raise CryptoUnavailableError('No crypto library available')
CryptoUnavailableError: No crypto library available
I have installed the pyOpenSSL library, and pycrypto library with the VCForPython compiler. I have also managed to edit all 3 app.yaml files in the LiClipse client to append:
libraries:
- name: pycrypto
version: "latest"
onto it.
This is what my code looks like so far with arbitrary credentials:
import json
import sys
import apiclient
from oauth2client import crypt
import ssl
import urllib2
from OpenSSL import crypto
HAS_OPENSSL = False
HAS_CRYPTO = False
try:
from oauth2client import crypt
HAS_CRYPTO = True
if crypt.OpenSSLVerifier is not None:
HAS_OPENSSL = True
except ImportError:
pass
from oauth2client.client import SignedJwtAssertionCredentials
client_email = 'example.apps.googleusercontent.com'
with open("C:\My Project-1234.p12") as f:
private_key = f.read()
credentials = SignedJwtAssertionCredentials(client_email, private_key,
'https://www.googleapis.com/auth/dfareporting')
from httplib2 import Http
I realize there is probably some excess in the beginning. I have not been able to get past this step.
I feel like I have tried everything and am still getting thrown the 'no crypto library' error.
Can anyone help? THANK YOU!
PS - I am using Windows 7 and Python 2.7 and LiClipse.
The above method was to make an API call as a 'service' Google account. I retried as an 'installed application' account with new credentials and a different way to make the API call which did not require any crypto type libraries.
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.