I'm trying to use Google API and the build instance has no attributes. Not even the sample project from Google works: https://developers.google.com/calendar/quickstart/python
I have tried to reinstall the libraries and forcing reinstall using:
"pip install --force-reinstall google-api-python-client".
Code from another Google site which does not work either:
from googleapiclient.discovery import build
API_KEY='my_apiKey'
GPLUS = build('plus', 'v1', developerKey=API_KEY)
TMPL = '''
User: %s
Date: %s
Post: %s
'''
items = GPLUS.event() # AttributeError: 'Resource' object has no attribute 'event'
The service you're building with the code you provided is the Google+ API Client. According to the docs for this client there's no attribute or function called event(), and so you get the corresponding error message when running your code. Take a look at those docs to see what you should be able to do with this client. There appears to be a quick sample on Github.
After some more testing i can verify that there exist attributes since the code is working but pylint in VS Code does not find the attributes and therefore mark them as non existing.
I have not idea though why this is happening.
Related
I want to get a list of all projects that a certain user on Gitlab has starred using the Gitlab API and Python (via python-gitlab).
The documentation from python-gitlab on users does not mention starred projects. It may be a user activity, but the documentation on user activities just refers to user activity managers and about that no further documentation is available.
With the Github API and pyGithub it's possible to achieve that using
import github
g = github.Github()
u = g.get_user()
u.get_starred()
However, with the Gitlab APi and python-gitlab I only get as far as:
import gitlab
gl = gitlab.Gitlab()
u = gl.users.get()
u.get_starred() # AttributeError
u.starred() # AttributeError
I think it might be possible because on a Gitlab website I can see the starred projects of a user. Example: https://gitlab.com/users/username/starred
I'm not sure if gitlab python package has it. But there is a REST API for the same. Refer this link https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
You can use requests module to do the GET and POST requests using python.
I am new in Splunk - as well as in Python and start working on Splunk Custom Module and I have taken reference from Splunk Site Custom Module. When I have created Same file structure using Visual Studio 2017 -> Python3 then its give me an error
import controllers.module not found
import splunk not found
import splunk.search not found
import splunk.util not found
import splunk.entity not found
import json from splunk.appserver.mrsparkle.lib not found
import lib.util as util not found
Note: I have already imported Splunk SDK using "pip install splunk-sdk" Still, I can't find any package in the project.
Please, anyone, guide me how to resolve above custom module package error.
If there is any readymade samples are available then please suggest a link.
Thanks in advance
You may be wasting your time. Splunk Modules have been deprecated for over a year and may become unsupported at any time.
The packages you are looking for should be part of Splunk. Have you installed it?
I believe Splunk does not support Python 3. Try 2.7.
Have you tried taking a look to simple_xml_exaples app for sourcecodeviewer implementation. I think it is a good approach for adding custom HTML + CCS + third party.js.
Furthermore it can be implemented in a custom dashboard.js
edit
Download Simple xml examples APP; in every example dashboard it can be seen that it has a custom component called sourceviewer, that is injected after the load time in every dashboard page.
For that a custom
dashboard.js
is created and inserted in APP/appserver/static so this will override the original
so then you can insert in every dashboard page the new needed components without even afecting the dashboard xml part and its functionalities as pdf generator.
I used that way in order to implement custom Nav as a SideBar.
I want to create my Pool using Python. I can do this when using an image (Ubuntu Server 16.04) from the marketplace, but I want to use a custom image (but also Ubuntu Server 16.04) -- one which I have prepared with the desired libraries and setup.
This is how I am creating my pool:
new_pool = batch.models.PoolAddParameter(
id=pool_id,
virtual_machine_configuration=batchmodels.VirtualMachineConfiguration(
image_reference=image_ref_to_use, # ??
node_agent_sku_id=sku_to_use),
vm_size=_POOL_VM_SIZE,
target_dedicated_nodes=_POOL_NODE_COUNT,
start_task=start_task,
max_tasks_per_node=_CORES_PER_NODE
)
I imaging that I need to use batch.models.ImageReference() to create my image reference... but I do not know how to use it.
Yes, I checked the documentation, which says the following:
A reference to an Azure Virtual Machines Marketplace image or a custom
Azure Virtual Machine image.
It lists the parameters as:
publisher (str)
offer (str)
sku (str)
version (str)
virtual_machine_image_id (str)
However, the parameter virtual_machine_image_id does not exists... In other words, batch.models.ImageReference(virtual_machine_image_id) is not allowed.
How can I use a custom image for my Pool?
UPDATE
So I figured out how to use a custom image... it turns out that no matter how many times I uninstall the azure python libraries and re-install them, the virtual_machine_image_id is never available.
I then went here downloaded the zip. Opened it up, checked the ImageReference class and low-and-behold, the virtual_machine_image_id was available in the __init__ function of the ImageReference class. I then downloaded the python wheel and used pip to install it. Boom it worked.
Or so I thought.
I then had to fight though trying to figure out what the node_agent_sku_id is... only by manually creating a Pool and seeing the Batch Node Agent SKU ID field did I manage to find it.
Now I am struggling with the Authentication...
The error I am getting is:
Server failed to authenticate the request. Make sure the value of
Authorization header is formed correctly including the signature.
AuthenticationErrorDetail: The specified type of authentication
SharedKey is not allowed when external resources of type Compute are
linked.
azure.batch.models.batch_error.BatchErrorException: {'lang':
'en-US', 'value': 'Server failed to authenticate the request. Make
sure the value of Authorization header is formed correctly including
the
signature.\nRequestId:f8c1a3b3-65c4-4efd-9c4f-75c5c253f992\nTime:2017-10-15T20:36:06.7898187Z'}
From the error, I understand that I am not allowed to use SharedKeyCredentials:
credentials = batchauth.SharedKeyCredentials(_BATCH_ACCOUNT_NAME,
_BATCH_ACCOUNT_KEY)
batch_client = batch.BatchServiceClient(
credentials,
base_url=_BATCH_ACCOUNT_URL)
What must I do?
UPDATE 2
OK. User fpark has informed me that I need to use:
from azure.batch import BatchServiceClient
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id=CLIENT_ID,
secret=SECRET,
tenant=TENANT_ID,
resource="https://batch.core.windows.net/"
)
batch_client = BatchServiceClient(
credentials,
base_url=BATCH_ACCOUNT_URL
)
to authenticate. Unfortunately, that the code above is described here and makes no reference to what CLIENT_ID et. al are.
I then managed to find another piece of documentation which appears to be the same thing: https://azure-sdk-for-python.readthedocs.io/en/v2.0.0rc3/resourcemanagementauthentication.html
That page pointed me to another webpage: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal
I followed that tutorial and managed to finally authenticate my application...
NOTE
When creating your application, the tutorial will tell you:
Provide a name and URL for the application. Select either Web app /
API or Native for the type of application you want to create. After
setting the values, select Create.
DO NOT select Native as you will not have the option to get an application key...
Required Minimum Azure Batch SDK
The azure-batch Python SDK v4.0.0 or higher is required. Typically with pip install --upgrade azure-batch you should just get the newest version. If that doesn't work you can add the --force-reinstall option to pip to force it (with --upgrade).
Node Agent Sku Id
Regarding the proper value for node_agent_sku_id, you need to use the list_node_agent_skus operation to see the mapping between operating systems and the node agent skus supported.
Azure Active Directory Authentication Required
Regarding the auth issue, you must use Azure Active Directory authentication to use this feature. It will not work with shared key auth.
Documentation
More information can be found in this guide, including all pre-requisites needed to enable custom images.
I am using azure-batch==9.0.0, and it turns out the docs are not updated as per the package itself. Using id instead of virtual_machine_image_id fixes the problem for me.
Trying in vain to access the Directory API in the Google Admin SDK (Reference). Upgrading the "google-api-python-client" package doesn't resolve it, as the Downloads > Installation > Python link instructs.
I also don't see in the documentation where it lists the programmatic name of the API, so I'm assuming it's "directory", but have also tried "directory.admin" and "admin.directory." I get the following exception when I try to run my test code:
apiclient.errors.UnknownApiNameOrVersion: name: directory version: v1
Could someone please assist with what I may be overlooking? Unfortunately, the "Quickstart" that provides the shell to access the API seems to be broken (Reference). When I select Python > Command-Line > Configure Project, I get an error that states "Sorry, unable to configure a project right now."
Here's the pertinent piece of code I'm using in my custom Directory library class:
class Directory(object):
def __init__(self, httpConnection):
self.service = build('directory', 'v1', http=httpConnection)
Is this just a case of no client library being available yet for the API? If so, when might that be available?
There's an issue where this new API isn't appearing in the list of supported APIs, but it is indeed there, you can access it from:
service = build('admin', 'directory_v1')
I am trying to set up my first ever API connection with Yelp, I am using GAE on Python. To do so, I used the following example: https://github.com/Yelp/yelp-api/blob/master/v2/python/search.py
At first I simply try to run the code by the following definition in my app.yaml
handlers:
- url: /search
script: search.py
However when I load the page it gives the following error: No module named oauth2. I have read through many of the topics that seem to cover this error but none really helped in resolving it. I also tried importing oauth2client which was mentioned in some answers however this was also not accepted.
The only thing that was accepted by the system was
from google.appengine.api import oauth
Therefore I tried to work with this module, but immediately ran into another problem. I filled out my credentials (consumer_key, consumer_secret, token, token_secret) by defining them as default value in the parser definition. To replicate the examples request on https://github.com/Yelp/yelp-api/tree/master/v2/python I also added a default value for 'term' (bars) and 'location' (sf).
When loading the page with this it however gives me the error 'module' object has no attribute 'Consumer', so this also doesn't seem to be the solution. As said this is my first time setting up such a system, so probably I am missing something obvious. Thanks a lot for your thoughts.
You cannot replace modules just like that, the script you are referring to works with the oauth2 library, which is different from GAE OAuth API (that's why you were getting the 'module' object has no attribute 'Consumer').
As explained in the README of the yelp-api, first you need to install the oauth2 module. Note that you need to copy the installed module (or source) to your GAE project in order to upload it to GAE when deploying.