Using Python with pygerrit2 Library to make API call to Gerrit From Power BI Desktop - python-3.x

I've recently started using power BI. I am trying to get data from Gerrit Rest Api Using Python. The following code works fine when I run it locally on my machine.
from requests.auth import HTTPDigestAuth
from pygerrit2.rest import GerritRestAPI
auth = HTTPDigestAuth('####', '##############')
rest = GerritRestAPI(url='https://gerrit.****.com', auth=auth)
changes = rest.get("/projects/?d")
In Power BI it doesn't cause any errors, but there are no results in the resulting Navigator Pane.
This seems to be the same problem outlined in this forum https://community.powerbi.com/t5/Desktop/Load-JSON-as-source-via-Python/td-p/485375
But I don't see any real resolution.
Is there any other way I can accomplish this?

I think you must change from:
rest = GerritRestAPI(url='https://gerrit.****.com', auth=auth)
To:
rest = GerritRestAPI(url='https://gerrit.****.com/a', auth=auth)
Without the "/a" the authentication doesn't work and you're getting an empty project list.
See more details about the authentication in the Gerrit documentation here.

Related

Unable to fetch the jira cloud assets through atlassian-python-api

I am working on a Atlassian Jira cloud product. I have a requirement to get the details of Jira cloud assets and update a field with some specific key-value pair. To achieve same, I have chosen python api to interact with Atlassian jira cloud and do those changes.
But, I am unable to access jira cloud assets using the atlassian-python-api which I have got from the https://pypi.org/project/atlassian-python-api/. Even I tried with different versions of it to achieve same.
Here is my sample code.
from atlassian import Jira
# Enter your Jira Cloud site URL and API token
JIRA_URL = "https://<your-domain>.atlassian.net"
JIRA_API_TOKEN = "<your-api-token>"
# Initialize the Jira API client
jira = Jira(
url=JIRA_URL,
username="",
password="",
cloud=True,
api_token=JIRA_API_TOKEN,
)
# Fetch a list of all assets
assets = jira.assets().search("")
# Print the asset details in a tabular format
print("Asset ID\tAsset Type\tName\tDescription")
for asset in assets:
print(f"{asset['id']}\t{asset['type']}\t{asset['name']}\t{asset['description']}")
But, getting below error.
assets = jira.assets().search("")
AttributeError: 'Jira' object has no attribute 'assets'
After that, I tried to fetch with different components like - jira.jira_service_desk().get_all_assets() , jira.get_all_assets() and jira.cloud.asset_management.get_all_assets() . But, everytime I am facing respective issue like 'Jira' object has no attribute <>`.
Could you please suggest a way make the bulk operations on jira-cloud-assets.
FYI, Even I went with the atlassian provided api - https://developer.atlassian.com/cloud/assetsapi/rest/api-group-assets/#api-asset-get - It also doesn't help to get them.
Expecting a solution to make write operations on Jira-Cloud assets.

Get a list of every Layer, in every Service, in every Folder in an ArcGIS REST endpoint

I have two ArcGIS REST endpoints for which I am trying to get a list of every layer:
https://rdgdwe.sc.egov.usda.gov/arcgis/rest/services
https://services1.arcgis.com/RLQu0rK7h4kbsBq5/ArcGIS/rest/services
These are not my organization's endpoints so I don't have access to them internally. At each of these endpoints there can be folders, services, and layers, or just services and layers.
My goal is to get a list of all layers. So far I have tried:
endpoints=(["https://rdgdwe.sc.egov.usda.gov/arcgis/rest/services",
"https://services1.arcgis.com/RLQu0rK7h4kbsBq5/ArcGIS/rest/services"])
for item in endpoints:
reqs = requests.get(item, verify=False)
# used this verify because otherwise I get an SSL error for endpoints[0]
soup =BeautifulSoup(reqs.text, 'html.parser')
layers = []
for link in soup.find_all('a'):
print(link.get('href'))
layers.append(link)
However this doesn't account for the variable nested folders/services/layers or services/layer schemas, and it doesn't seem to be fully appending to my layers list.
I'm thinking I could also go the JSON route and append ?f=psjon . So for example:
https://rdgdwe.sc.egov.usda.gov/arcgis/rest/services/?f=pjson would get me the folders
https://rdgdwe.sc.egov.usda.gov/arcgis/rest/services/broadband/?f=pjson would get me all the services in the broadband folder
and
https://rdgdwe.sc.egov.usda.gov/arcgis/rest/services/broadband/CDC_5yr_OpioidOverDoseDeaths_2016/MapServer?f=pjson would get me the CDC_OverDoseDeathsbyCounty2016_5yr layer in the first service (CDC_5yr_OpioidOverDoseDeaths_2016) in the broadband folder.
Any help is appreciated. I put this here vs in the GIS stack exchange as it seems a more python question than geospatial.
I don't really agree this is a Python question because there doesn't seem to be any issue with how to use the various Python libraries. The main issue appears to be how do you work with Esri's REST API. Seeing that Esri is very much a GIS company and their REST API is very much a GIS API, I think GIS StackExchange would have been a better forum for the question.
But, since we are here now....
If you are going to continue working with Esri's REST API with Python, I strongly encourage you to read up on Esri's ArcGIS API for Python. At its core, the ArcGIS API for Python is a Python wrapper for working with Esri's REST API. Unless someone has very basic needs, rolling one's own Python code for Esri's REST API isn't time well spent.
If you are set on rolling your own, I strongly encourage you to read Get started -- ArcGIS REST APIs | ArcGIS Developers. The documentation describes the structure of the REST API, syntax, and it includes some examples.
The following isn't pretty, it is meant more to help you connect the dots when reading Esri's documentation. That said, it will give you a list of Map Services on an ArcGIS Server site and the layers for those services.
import json
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
services = {}
services_endpoint = "https://fqdn/arcgis/rest/services"
req = requests.get(f"{services_endpoint}?f=json", verify=False)
svcs_root = json.loads(req.text)
for fld in svcs_root['folders']:
req = requests.get(f"{services_endpoint}/{fld}?f=json", verify=False)
svcs_fld = json.loads(req.text)
for svc in svcs_fld['services']:
if svc['type'] not in ('MapServer'): continue
req = requests.get(f"{services_endpoint}/{svc['name']}/{svc['type']}?f=json", verify=False)
svc_def = json.loads(req.text)
services.update({svc['name']:{'type':svc['type'], 'layers':svc_def['layers']}})
for svc in svcs_root['services']:
if svc['type'] not in ('MapServer'): continue
req = requests.get(f"{services_endpoint}/{svc['name']}/{svc['type']}?f=json", verify=False)
svc_def = svc = json.loads(req.text)
services.update({svc['name']:{'type':svc['type'], 'layers':svc_def['layers']}})
As part of developing GISsurfer (https://gissurfer.com) I was faced with that exact problem but for any ArcGIS server that did not require login creds. My solution was to write PHP code to 'walk the tree' to find all services.

Python wrapper coinbase api errors

So I am trying to create a new wallet using the Python wrapper for the coinbase api.
My current code is this:
from coinbase.wallet.client import Client
client = Client('API-Key',
'SECRET',
api_version='2019-12-30')
# Get your primary coinbase account
primary_account = client.get_primary_account()
address = primary_account.create_address()
print(address)
When trying to use the code above, I always get the error:
coinbase.wallet.error.AuthenticationError: APIError(id=authentication_error): request timestamp expired
My guess is that the wrapper is not passing the right timestamp.
On the github page for this wrapper, it says that the current build is failing. I don't know how to fix this. The github hasn't had any recent updates. I tried to look at the client file to see if I could fix it myself, but I have had no luck.
I was facing the same issue but, as I've understood from the various contributions, the problem is due to the difference between the local OS time and Coinbase servers time. Besides 30 seconds of epochs difference, coinbase server returns the tedious timestamp expiration error!
I've found python code to update local Windows time based on various ntp servers ntp_update_time.py (shared by gilmotta). Launching the ntp_update_time's code before running coinbase client again makes the error disappear and everything work as indicated in Coinbase API references!!!

Get list of application packages available for a batch account of Azure Batch

I'm making a python app that launches a batch.
I want, via user inputs, to create a pool.
For simplicity, I'll just add all the applications present in the batch account to the pool.
I'm not able to get the list of available application packages.
This is the portion of code:
import azure.batch.batch_service_client as batch
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id='xxxxx',
secret='xxxxx',
tenant='xxxx',
resource="https://batch.core.windows.net/"
)
batch_client = batch.BatchServiceClient(
credentials,
base_url=self.AppData['CloudSettings'][0]['BatchAccountURL'])
# Get list of applications
batchApps = batch_client.application.list()
I can create a pool, so credentials are good and there are applications but the returned list is empty.
Can anybody help me with this?
Thank you,
Guido
Update:
I tried:
import azure.batch.batch_service_client as batch
batchApps = batch.ApplicationOperations.list(batch_client)
and
import azure.batch.operations as batch_operations
batchApps = batch_operations.ApplicationOperations.list(batch_client)
but they don't seem to work. batchApps is always empty.
I don't think it's an authentication issue since I'd get an error otherwise.
At this point I wonder if it just a bug in the python SDK?
The SDK version I'm using is:
azure.batch: 4.1.3
azure: 4.0.0
This is a screenshot of the empty batchApps var:
Is this the link you are looking for:
Understanding the application package concept here: https://learn.microsoft.com/en-us/azure/batch/batch-application-packages
Since its python SDK in action here: https://learn.microsoft.com/en-us/python/api/azure-batch/azure.batch.operations.applicationoperations?view=azure-python
list operation and here is get
hope this helps.
I haven't tried lately using the Azure Python SDK but the way I solved this was to use the Azure REST API:
https://learn.microsoft.com/en-us/rest/api/batchservice/application/list
For the authorization, I had to create an application and give it access to the Batch services and the I programmatically generated the token with the following request:
data = {'grant_type': 'client_credentials',
'client_id': clientId,
'client_secret': clientSecret,
'resource': 'https://batch.core.windows.net/'}
postReply = requests.post('https://login.microsoftonline.com/' + tenantId + '/oauth2/token', data)

Python2 connexion framework - controller in directory structure

I am playing around with using the connexion framework to setup a REST API access for my application.
My application is is built on python2, I installed the connexion framework for python2 and played around with the yaml file via the editor (editor.swagger.io). I downloaded the Python Flask server code, converted it to be compatable with Python2 and tested for a single controller.
When the controller is placed in the same directory as the place where the server is run. Everything was fine - all routes were added and working as expected. I then proceeded to split the controller based on some business logic and wanted a tree structure for each controller.
Something like
myapp/api/magic1/magic1_controller.py
myapp/api/magic2/magic2_controller.py
and so on.
This does not work for python2. It seems to work for python3. Any ideas why?
I get the following error from logs
DEBUG:connexion.api:Security Definitions: {}
DEBUG:connexion.api:Validate Responses: False
DEBUG:connexion.api:Creating API blueprint: /api
DEBUG:connexion.api:Adding swagger.json: /api/swagger.json
DEBUG:connexion.api:Adding swagger-ui: /api/ui/
DEBUG:connexion.api:Adding /api/magic1/{name}...
ERROR:connexion.api:Failed to add operation for GET /api/magic1/{name}
In the yaml config file I add the OperationId as api.magic1.func1() and so on.
Following the information you provided here the operationId should be set to api.magic1.magic1_controller.func1 and not api.magic1.magic1.func1().
You are missing to provide more details about your problem. Code snippets would help to guide you in a more detailed solution.

Resources