I have a question regarding contact creation using the python Google data API.
I am trying the example for contact creation with python, exactly like it is in the documentation page (https://developers.google.com/google-apps/contacts/v3/#creating_contacts)
So, i created the client as following:
email='<my gmail uid>'
password='<my gmail pwd>'
gd_client = gdata.contacts.client.ContactsClient(source='GoogleInc-ContactsPythonSample-1')
try:
gd_client.ClientLogin(email, password, gd_client.source)
except gdata.client.BadAuthentication:
print 'Invalid user credentials given.'
gd_client = None
Then i executed the function using:
create_contact(gd_client)
What i get from this call is:
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "<ipython console>", line 23, in create_contact
AttributeError: 'module' object has no attribute 'PostCode'
So I want to ask whether i am doing something wrong, whether this is a known bug, or whether the documentation is simply outdated.
Thanks.
p.s. a small comment, i think a better wrapping of the Google data API in the python library could be useful. I spent significant time in finding, within the API implementation, what fields should be set (directly!) and what classes should be used to assign them.
Ok, it seems that i can answer my question, which is partly a duplicate of
how to create google contact?
It turns out that the sample code in the documentation is invalid (thanks, Google)
PostCode should be Postcode, and the instant messaging address is also incorrect.
Removing that, it completes successfully
Related
I followed this link to doc to create environment of my own.
But when i run this
from mlagents_envs.environment import UnityEnvironment
env = UnityEnvironment(file_name="v1-ball-cube-game.x86_64")
env.reset()
behavior_names = env.behavior_spec.keys()
print(behavior_names)
Game window pop up and then terminal show error saying
Traceback (most recent call last):
File "index.py", line 6, in <module>
behavior_names = env.behavior_spec.keys()
AttributeError: 'UnityEnvironment' object has no attribute 'behavior_spec'
despite the fact that this is the exact snippet as shown in the documentation.
I created environment by following this (it make without brain) and i was able to train the model by .conf file. Now i wanted to connect to python API.
You need to use stable documents and stable repo( RELEASE_TAGS ) to achieve stable results. Unity ML Agents changes it's syntax every few months so that is problem if you are following master branch.
env.get_behavior_spec(behavior_name: str)
Should solve your problem.
https://github.com/Unity-Technologies/ml-agents/blob/release_2/docs/Python-API.md
I am doing initial exploration in the SoCo module which is a Python API for Sonos. Following the tutorial I do
>>> speakers = soco.discover()
>>> speaker = speakers.pop()
>>> speaker.player_name
'Portable'
>>> speaker.ip_address
'192.168.0.11'
>>> speaker.get_current_transport_info()['current_transport_state']
'STOPPED'
So far, so good. Now, still following the documentation, I do
>>> speaker.music_library.list_library_shares()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'MusicLibrary' object has no attribute 'list_library_shares'
and, sure enough, dir(speaker.music_library) confirms there is no such method.
But the documentation for this class says:
Listing and deleting music library shares
Music library shares are the local network drive shares connected to Sonos, which host the
audio content in the Sonos Music Library.
To list the shares connected to Sonos, use the list_library_shares()
method as follows:
››› device.music_library.list_library_shares()
['//share_host_01/music', '//share_host_02/music']
The result is a
list of network share locations.
Now either the documentation is badly out of step with the version I just downloaded (0.18.1; it says not), or I need another pair of eyes to point out what I am doing wrong.
I asked this question also on the SoCo Google group and this is the answer I got:
This function is not included in v0.18.1, but will be in the upcoming
v0.19 release. It's unintuitive but you need to look at the v0.18.1
documentation at:
http://docs.python-soco.com/en/v0.18.1/api/soco.music_library.html
... not the 'latest' version of the documentation.
I forbear to remark on the wisdom of pointing readers of the Getting Started page in the wrong direction.
anyone can help me?
I want to retrieve data from the Firebase Realtime Database
my main.py:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate ("serviceAccountKey.json")
firebase_admin.initialize_app (cred, {"databaseURL": "https://myDatabase.firebaseio.com/"})
ref = db.reference ("user")
for u in ref:
print (ref.get())
and I get an error message like this
Traceback (most recent call last):
File "main.py", line 10, in <module>
for u in ref:
TypeError: 'Reference' object is not iterable
I am just learning Firebase by using Python.
I hope you can help, thank you :)
Based on your code, you are trying to print the data of each user under the /user key in your database. The code db.reference("user") returns an object that refers to a location on your database and doesn't hold any data. To get a list of each user, you would use a variation of the following code:
ref = db.reference("user")
data = ref.get() # get data from db
for u in data # iterate children of data
print(u)
This answer is to help you debug such errors in future by yourself. :)
The error is telling you that you have a "TypeError", the first thing you should probably do is check the type of ref by doing print(type(ref)), is that an iterable? Most likely no, which is why you get the error. The next step should be checking either the docs online or locally the functions provided by ref. You could do this by starting a new shell, typing all the commands till before the for loop and the dir(ref). You will see a wide range of functions there, which one seems most legit of the names that would "get" you the data? get of course. There you go. :)
According to Google's OAUTH API documentation, the userinfo.profile and userinfo.email scopes have been deprecated in favor of using profile and email. There is a lot of information from other API users about this switch as well.
However, when trying to use the People API, I get this error:
2016-02-22 13:01:25,044 :Exception on /admin/testbank/settings [GET]
Traceback (most recent call last):
(Flask traceback omitted...)
File "/home/somedev/testweb/views/admin_view.py", line 78, in admin_view
res_acct_info = people_service.people().get(userId='me').execute()
File "/home/somedev/env/lib/python3.4/site-packages/googleapiclient/discovery.py", line 676, in method
raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "userId"
Looking at the Google API sample, this should be the right call. However, dumping parameters.argmap within the library's discovery.py shows that userId does not exist. What am I doing wrong?
(Note: I'm trying to tag google-people, since this is where the API pages suggest, but I don't have enough rep to tag this. Could someone else add this tag for me?)
It turns out that I've been blind to the exact code I'm reading... all of these examples (particularly Google's example) have been using the Google+ API, which does indeed have the userId argument.
For reference, the "old way" is by using the oauth2/userinfo service:
service = build('oauth2', 'v2', http=http)
user = users_service.userinfo().get().execute()
name = user.get('name')
email = user.get('email')
You can use the Google+ API to get the same information - it will work, even if the user does not have a Google+:
service = discovery.build("plus", "v1", http=http)
user = service.people().get(userId='me').execute()
# This assumes that user['emailAddresses'] exists and
# has at least one element...
name = user.get('displayName')
email = user.get('emailAddresses')[0].get("value")
At the time of writing, it seems that the People API was released recently (February 10th, 2016)! It makes sense that there wouldn't be much documentation about it...
To use the newer People API (and maybe claim cleanliness from Google+), this is the correct way to fetch the current user's information:
service = discovery.build('people', 'v1', http_auth)
user = people_service.people().get(resourceName='people/me').execute()
# This assumes that user['names'] and user['emailAddresses']
# exists and has at least one element...
name = user.get('names')[0].get("displayName")
email = user.get('emailAddresses')[0].get("value")
resourceName replaces userId in the People API. It has a similar purpose (to identify the current user or another user), but has a different format, as seen with using 'people/me' versus just 'me'.
Both the Google+ and the newer People API simply require the email and profile scopes. However, unlike the former userinfo API, you need to manually enable the Google+ API and/or the People API in order to use them.
tl;dr: Google+ API uses userId='me', new People API uses resourceName='people/me', you should use one of these supported APIs - both return the same information, just in a slightly different format!
I've been trying to create content in my plone site using the Dexterity tool createContentInContainer.
I wrote a script that runs under my zopepy instance, and it accomplishes the following:
Selects data from a SQL table.
Creates a list of tuples that mirrors the custom content type defined in my product.
I know I'm extremely naive in my approach, but I've created a connection to the applications database by:
storage = FileStorage.FileStorage('.../var/filestorage/Data.fs')
db = DB(storage)
conn = db.open()
dbroot = conn.root()
I'm trying to create content by:
createContentInContainer(dbroot['Application']['myapp']['existingfolder'], portal_type, checkConstraints=False, content=item)
portal_type is previously set to my custom content type. item has been both the list of tuples passed to the content's interface (which throws a Could not adapt TypeError) as well as an unregistered adapter that inherits from the interface.
The interface for the type is registered in mysite.Widget.xml in profiles/defualt/types, but the script keeps throwing:
Traceback (most recent call last):
File "./bin/zopepy", line 345, in <module>
execfile(__file__)
File "importdex.py", line 105, in <module>
createContentInContainer(dbroot['Application']['myapp']['existingfolder'], portal_type, checkConstraints=False, content=item)
File "env/mysite/eggs/plone.dexterity-1.0-py2.7.egg/plone/dexterity/utils.py", line 149, in createContentInContainer
content = createContent(portal_type, **kw)
File "env/mysite/eggs/plone.dexterity-1.0-py2.7.egg/plone/dexterity/utils.py", line 105, in createContent
fti = getUtility(IDexterityFTI, name=portal_type)
File "env/mysite/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 169, in getUtility
raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass plone.dexterity.interfaces.IDexterityFTI>, 'mysite.Widget')
As I've mentioned, I know I'm extremely naive in my approach, and I probably deserve a slap on the hand. I apologize if I've presented my question in a confusing manner.
My questions are these:
Can I instantiate createContentInContainer from zopepy? Is my rigged connection enough or does the script need to be run within the application to inherit stuff that Dexterity/FTI needs to accomplish what I'm asking?
Do I need an adapter? The one i have inherits from grok.Adapter and passes the interface to grok.provides and grok.context, but should it declare properties based on the entirety of the content schema?
The list of tuples is arbitrary. It just seemed like the thing to do given the structure of the ZODB. If I declare the schema of the content type as properties in a registered adapter, the data should be crafted to conform to attributes of an object (the adapter), right?
You need to set up a little more context for your code to work. The Plone site acts as a local component registry, for example.
You are also better off using the bin/instance run [scriptname] command, it'll set up the database connection for you and pass the root object as app to your script. In that script, use the following boilerplate to get the rest of the scaffolding up:
import transaction
from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest
from AccessControl.SecurityManagement import newSecurityManager
plone_site_id = 'Plone' # Adjust as needed.
app = makerequest(app)
site = app[plone_site_id]
setSite(site)
user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)
With these in place you'll have everything you need to run your code. Don't forget to call transaction.commit() at the end. Your Plone site is reachable in the local variable site.