I am tring to write data to my firebase project using Python,
I found a code which works for the guy who show it but it does not work for me and I do not understand what the problem is.
This is the code:
from firebase import firebase
FBConn = firebase.FirebaseApplication('project-address-here',None)
while True:
price=int(input("what is the price?"))
data_to_upload = {
'Price' : price
}
result= FBConn.post('/MyTestData/',data_to_upload)
print(result)
when i run the code i get this message:
Traceback (most recent call last):
File "c:/Users/username/Desktop/folder/file.py", line 1, in module
from firebase import firebase
File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\firebase_init_.py", line 3
from .async import process_pool
^
SyntaxError: invalid syntax
What does this mean? how could it be that for him it works and for me it doesn't?
Looks like a problem in the firebase module, which is not the official one by Google.
The firebase module from pypy hasn't been updated for more than 18 months.
Take a look the official SDK documentation at: https://firebase.google.com/docs/firestore/quickstart#python
Related
from geopy.geocoders import ArcGIS
from arcgis.geocoding import reverse_geocode
arcgis = ArcGIS()
results = reverse_geocode(location={"x": 103.876722, "y": 1.3330736})
print(results)
When I run this script in python, I get the following error.
Traceback (most recent call last):
File "C:\Users\18102\RentScraping\newMarketRequests.py", line 22, in <module>
results = reverse_geocode(location={"x": 103.876722, "y": 1.3330736})
File "C:\Users\18102\AppData\Roaming\Python\Python310\site-packages\arcgis\geocoding\_functions.py", line 1457, in reverse_geocode
geocoder = arcgis.env.active_gis._tools.geocoders[0]
AttributeError: 'NoneType' object has no attribute '_tools'
I pip installed the arcgis library, which I have used before for geocoding on a different project, but the reverse geocoding isn't working. I saw some documentation that had a few variations on how to provide the location parameter. I also tried reverse_geocode([103.876722, 1.3330736]) and got the same result. I think there might be something that got updated and the documentation I'm referencing is out of date. Any advice?
I am trying to use python to connect with SF.
Saw some articles that show how to use it with beatbox library and I did install it.
However when trying to run simple code I'm getting error below.
Traceback (most recent call last):
File "c:/Users/user/hello/.vscode/hello.py", line 16, in <module>
import beatbox
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\beatbox\__init__.py", line 1, in <module>
from _beatbox import _tPartnerNS, _tSObjectNS, _tSoapNS, SoapFaultError, SessionTimeoutError
ModuleNotFoundError: No module named '_beatbox'
I navigate to the folder where the beatbox is installed and I see there the file _beatbox.py.
I think the file __init__.py try to import _beatbox but cannot find it for some reason.
Any idea how to solve it? What I'm missing?
Code:
import beatbox
sf_username = "xxxxxx"
sf_password = "xxxxxx"
sf_token = "xxxxxx"
def getAccount():
sf = beatbox._tPartnerNS
sf_client = beatbox.PythonClient()
password = str("%s%s" % (sf_password, sf_token))
sf_client.login(sf_username, sf_password)
accQuery = "Select Id,Name From Account limit 5"
queryResult = sf_client.query(accQuery)
print ("query result: " + str(queryResult[sf.size]))
for rec in queryResult[sf.records:]:
print str(rec[2]) + " : " + str(rec[3])
return
Can close the case. I first found that in python 3+ should use beatbox3. But then found additional errors (possible compatibility issues).
Since I notice it taking me too long, instead I tried using library simple-salesforce 0.74.2 to connect, and it worked perfect.
Probably, Python does not know where to search for the module. By default, only the sitepackages directory and your working directory is searched. You can resove this by placing a symbolic link to the beatbox package or moving it to the sitepackages directory
If you change the sitepackage folder name from "beatbox" to "_beatbox" this will solve your problem. You can then import it as: "import beatbox" and it will load in Python.
TLDR : using QGIS, I'm trying to develop a python plugin to update a database. Unfortunately I get immediatly an error : Traceback (most recent call last):
File "", line 1, in
NameError: name 'QgsDataSourceUri' is not defined
More detailed:
I work on QGIS2.18 to develop a plugin to update some data located on a postgres database.
for this, I want to use this kind of code:
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtCore import QSettings
from PyQt4.QtCore import QSettings
from qgis.core import QgsVectorLayer, QgsDataSourceURI
uri = QgsDataSourceUri()
# set host name, port, database name, username and password
uri.setConnection(hote_IP, "5432", base_de_donnee, utilisateur, mot_de_passe)
# set database schema, table name, geometry column and optionally
# subset (WHERE clause)
#uri.setDataSource("public", "roads", "the_geom", "cityid = 2643")
uri.setDataSource("", sql, "geom", "", "gid")
vlayer = QgsVectorLayer(uri.uri(), zapm, "postgres")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
(I got the code from the net, I'll adapt it later on)
My problem : when I try to run this code on the Python console of QGIS, I immediatly get the error
Traceback (most recent call last):
File "", line 1, in
NameError: name 'QgsDataSourceUri' is not defined
even when I only run the import and the line uri = QgsDataSourceUri(), I get the same error message.
I have not been able to find out how to correct this issue.
problem of installation of QGIS? of python? bad imports?
Config:
qgis 2.18.20
python 3.6.5
If anyone has an idea on how to solve this, I would be really glad.
Thanks,
Erwann
You simply are using the wrong class name. It should be uri = QgsDataSourceURI() instead of uri = QgsDataSourceUri() because you've imported QgsDataSourceURI and not QgsDataSourceUri
QGIS and QT Python classes are case-sensitive. You can confirm the exact syntax looking at QGIS 2.18 related API.
So I installed the facebook module, realized it was the wrong one, used pip to uninstall and then installed facebook-sdk. Here is my code:
import facebook
token = '[token]'
graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list
and get
Traceback (most recent call last):
File "C:\Users\mgraves\Desktop\facebook.py", line 1, in <module>
import facebook
File "C:\Users\mgraves\Desktop\facebook.py", line 5, in <module>
graph = facebook.GraphAPI(token)
AttributeError: 'module' object has no attribute 'GraphAPI'
When looking this up, EVERY result says to uninstall facebook and facebook-sdk and reinstall facebook-sdk. And I have, many many times. I searched /python27/ for facebook afterwards to make sure the files were gone.
Is there any way on a windows machine to trace back where I am importing "facebook" from?
Module objects have a __file__ attribute, and the object representation also includes the file:
print facebook
print facebook.__file__
In your case, you are importing your own script; you named it facebook as well and are masking the installed module:
File "C:\Users\mgraves\Desktop\facebook.py", line 1, in <module>
import facebook
File "C:\Users\mgraves\Desktop\facebook.py", line 5, in <module>
graph = facebook.GraphAPI(token)
Note the filename in the first line, then the fact that the same file is used for that import. Python stores the main script as __main__, so importing the script itself results in another module being created for the actual filename.
I am importing boto.dynamodb.table and getting a syntax error. I don't see how it is related to what I'm doing. I haven't implemented / used it and yet upon launching it finds a syntax error.
The error from my console looks like this:
File "api.py", line 10, in <module>
import dynamoAccess
File "/Users/tai/Documents/workspace/testSelenium/testS/dynamoAccess.py", line 6, in <module>
from boto.dynamodb2.table import Table
File "/Library/Python/2.7/site-packages/boto/dynamodb2/table.py", line 3, in <module>
from boto.dynamodb2.fields import (HashKey, RangeKey,
File "/Library/Python/2.7/site-packages/boto/dynamodb2/fields.py", line 1, in <module>
from boto.dynamodb2.types import STRING
File "/Library/Python/2.7/site-packages/boto/dynamodb2/types.py", line 4, in <module>
from boto.dynamodb.types import Dynamizer
File "/Library/Python/2.7/site-packages/boto/dynamodb/types.py", line 112
]
^
SyntaxError: invalid syntax
The code that I believe this is related to is the first few lines (aka the dynamo table import) of dynamoAccess:
This is what I have:
import cleaner
import datetime
import awsAccess
import boto
from boto import dynamodb2
from boto.dynamodb2.table import Table
#create a connection to amazon s3
#aws_access_key_id=getenv('AWS_ACCESS_KEY');
#aws_secret_access_key=getenv('AWS_SECRET_KEY');
#aws_dynamo_region=getenv('DYANAMO_REGION')
#for running in pydev
aws_access_key_id=awsAccess.aws_access_key_id
aws_secret_access_key=awsAccess.aws_secret_access_key
aws_dynamo_region=awsAccess.aws_dynamo_region
decompiled_dynamo_table="decompiled_swfs"
text_dynamo_table="decompiled_swf_text"
image_dynamo_table="images_decompiled"
_dynamo_table="decompiled_swf_text"
Has anyone encountered this? I haven't modified the boto file.
Edit:
resinstalled boto but still getting the error:
Name: boto
Version: 2.31.1
Edit 2: Solved see answer below. Boto had a bug
Fixed - I replaced the boto dynamodb/types.py file with the one in github: https://github.com/boto/boto
There was a ] out of place that needed to be fixed. This was already fixed in the github version but apparently not yet pushed to pip
I believe that this may occur for other people due to the above error. If you encounter this simply update your file from github (or edit it yourself)