Pyhton USGS EarthExplorer API not Working - python

I am trying to write a pyhton script that I would have my login credientals to log into USGS earth explorer and use their API to search for images in a dataset and give me the results, I am not sure what I want to do with the results but I am having trouble even searching for anything using the api.
Here is the code I have:
from usgs import api
#USGS EarthExplorer username and password
username = ''
password = ''
# Connect to the USGS EarthExplorer API using username and password
# This will prompt you to enter your credentials if you haven't set them up already
api.login(username, password)
# Search for Landsat 8 images within a specific date range and location
# In this example, we are searching for images over Washington, D.C. from January 1, 2022 to February 1, 2022
result = api.search(dataset='LANDSAT_8_C1',
node='EE',
latitude=38.9072,
longitude=-77.0369,
start_date='2022-01-01',
end_date='2022-02-01')
# Print the result to see the available images
print(result)
As a note I have removed my login so that is not the issue. When I go to run this code I get the following error:
Traceback (most recent call last):
File "c:\Users\edwar\OneDrive\Research\MyCode\connect.py", line 13, in <module>
result = api.search(dataset='LANDSAT_8_C1',
^^^^^^^^^^
AttributeError: module 'usgs.api' has no attribute 'search'
I have looked up this error and read through the documentation however maybe I am missing something that someone can point out for me? I also have an API key is there something I need to do with that or is the login credientials enough?
I have gotten my idea to use api.search from here . This documentation does the same thing I have it is just formatted differently but the methods are the same.

Related

Error when calling the Azure Quota SDK for python for Standard NCASv3_T4 Family types of instances

I have been trying to call the quota.get() method and it works for all resource names that doesn't have a space or underscore in the name, for example: "standardNCFamily" works but not for the rest like, "Standard NCASv3_T4 Family" does not.
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from azure.identity import DefaultAzureCredential
from azure.mgmt.quota import AzureQuotaExtensionAPI
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-quota
# USAGE
python quotas_list_quota_limits_for_compute.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AzureQuotaExtensionAPI(
credential=DefaultAzureCredential(),
)
response = client.quota.list(
scope="subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Compute/locations/eastus",
)
for item in response:
print(item)
# x-ms-original-file: specification/quota/resource-manager/Microsoft.Quota/preview/2021-03-15-preview/examples/getComputeQuotaLimits.json
if __name__ == "__main__":
main()
This is the sample code from samples repo in the Azure python github here
And this is the error I get when I call for the NCAS_v3 type of instances:
Traceback (most recent call last):
File "/Users/name/PycharmProjects/Virga-API/azure/trytry.py", line 35, in <module>
main()
File "/Users/name/PycharmProjects/Virga-API/azure/trytry.py", line 25, in main
response = client.quota.get(
File "/Users/name/PycharmProjects/Virga-API/venv/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "/Users/name/PycharmProjects/Virga-API/venv/lib/python3.10/site-packages/azure/mgmt/quota/operations/_quota_operations.py", line 237, in get
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (InvalidResourceName) Name %60%60Standard%20NCASv3_T4%20Family%60%60 is not valid resource name.
Code: InvalidResourceName
Message: Name %60%60Standard%20NCASv3_T4%20Family%60%60 is not valid resource name.
I've been at it for hours trying different configurations for the names but can't seem to find it.
The documentation doesn't mention anything either.
Any help would be awesome!
It seems that your name contains underscores and spaces and you're accessing it in the wrong way without any casting and space safety resource, make sure that your resource name should match the name of the resource you want to retrieve information about, and it should be formatted correctly. For example, to retrieve information about Standard NCASv3_T4 Family instances, you should pass "Standard NCASv3_T4 Family" as your resource name to the quota.get() method, so your code should be like quota.get("Standard NCASv3_T4 Family") it should work anyway, if not, make sure you imported the correct resource type when calling the quota.get() method. The resource type you're using should match the type of that resource that you're trying to retrieve information about. For example, if you're trying to retrieve information about Standard NCASv3_T4 Family instances, you should use the resource type
"virtualMachineScaleSets" resource type, and also don't forget to check standard documentation they're always a good resource for everything!!

Pywin32 update word document via scheduler

I have some simple code which opens a word document, updates the fields in it, then closes it. This code works correctly when I manually run it, however when I run it via the SQL Server Agent, I get an error. The user that SQL Server Agent runs with is the same user I am logged in with when running manually. I know the agent can 'see' the document because earlier code used in the task actually creates this document.
Code:
import win32com.client
word = win32com.client.DispatchEx("Word.Application")
filePath = "\\\\network\\data\\file.docx"
doc = word.Documents.Open(filePath)
doc.TablesOfContents(1).Update()
doc.Close(SaveChanges=True)
word.Quit()
Error:
Executed as user: DOMAIN\User. Traceback (most recent call last):
File "\\network\data\file.docx", line 8, in
doc.TablesOfContents(1).Update() AttributeError: 'NoneType' object
has no attribute 'TablesOfContents'
Why might this behavior happen?
For anyone in the future that might get this issue, I fixed it like this:
Open dcomcnfg Navigate to Component Services>Computers>My
Computer>DCOM Config>Microsoft Word 97-2003 Document
Right-click, click Properties
Select the Identity Tab
Select 'The Interactive User'

PyGoogleVoice API Raises TypeError when trying to login

I am trying to mess with the pygooglevoice api and am trying to run the example call program on the documentation website:
from googlevoice import Voice
from googlevoice.util import input
voice = Voice()
voice.login()
outgoingNumber = input('Number to call: ')
forwardingNumber = input('Number to call from [optional]: ') or None
voice.call(outgoingNumber, forwardingNumber)
if input('Calling now... cancel?[y/N] ').lower() == 'y':
voice.cancel(outgoingNumber, forwardingNumber)
I then get the following error when voice.login() tries to execute:
File "C:\Users\<USER>\AppData\Local\Programs\Python\Python35\lib\configparser.py", line 406, in _interpolate_some
rawval = parser.get(section, option, raw=True, fallback=rest)
TypeError: get() got an unexpected keyword argument 'raw'
I am currently using Python 3.5 on a Windows 10 machine. I am also 90% sure I configured my .gvoice file properly in my user home directory. I have the email, password, and forwardingnumber all written out in that file.
Has anyone else had this issue? Am I using a deprecated API?
I found a more recent version of the library here: https://github.com/pettazz/pygooglevoice
This did fix my configparser error but I am now encountering another problem of a different nature. However my primary problem is fixed.

Python API Call : pyzillow : Extract Real estate information from Zillow and convert it into a Shapefile

I am trying to extract the real-estate information from Zillow using the pyzillow API.I am trying to get a point shapefile having all the houses for sale information so that I can interpret them in ArcGIS. Since, I do not have the facility to convert directly into a shapefile I am using the methodology of API call. I used the package pyzillow ( https://pypi.python.org/pypi/pyzillow/0.5.5). I am interested in extracting the real-estate data for entire Richardson (http://www.zillow.com/richardson-tx/).
I used the below code for making API call:
from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults
address = 'Richardson TX'
zipcode = '75080'
zillow_data = ZillowWrapper('X1-ZWz1fjckjdd8gb_a2eph')
deep_search_response = zillow_data.get_deep_search_results(address,zipcode)
result = GetDeepSearchResults(deep_search_response)
result.zillow_id # zillow id, needed for the GetUpdatedPropertyDetails
When I executed the above code I am receiving the error:
"C:\Program Files\ArcGIS\Pro\bin\Python\env\arcgispo-py3\python.exe" C:/Users/Rvg296/PycharmProjects/Final_Project/Multi-Criteria.py
Traceback (most recent call last):
File "C:/Users/Rvg296/PycharmProjects/Final_Project/Multi-Criteria.py", line 5, in <module>
deep_search_response = zillow_data.get_deep_search_results(address,zipcode)
File "C:\Users\Rvg296\AppData\Roaming\Python\Python34\site-packages\pyzillow\pyzillow.py", line 31, in get_deep_search_results
return self.get_data(url, params)
File "C:\Users\Rvg296\AppData\Roaming\Python\Python34\site-packages\pyzillow\pyzillow.py", line 82, in get_data
raise ZillowError(int(response.findall('message/code')[0].text))
pyzillow.pyzillowerrors.ZillowError
Process finished with exit code 1
When I tried to figure out what was the issue, I found that the address is not able to take the entire city or state. It is able to take only the street information and zip code and then list the details.
The code that you have above is correct and should work. However, the part that is creating the error is that the address needs to be an address of a home, and not the city. If you put in a home address, as opposed to the city, your code should work just fine.
For example, the following below should work.
from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults
address = '1600 Pennsylvania Ave NW, Washington, DC'
zipcode = '20006'
zillow_data = ZillowWrapper('X1-ZWz1fjckjdd8gb_a2eph')
deep_search_response = zillow_data.get_deep_search_results(address,zipcode)
result = GetDeepSearchResults(deep_search_response)
print(result.zillow_id)
Hope that helps!

Python suds error creating object

Trying to work with the echosign SOAP API.
The wsdl is here: https://secure.echosign.com/services/EchoSignDocumentService14?wsdl
When I try to create certain objects, it appears to not be able to find the type, even after listing it in print client
import suds
url = "https://secure.echosign.com/services/EchoSignDocumentService14?wsdl"
client = suds.client.Client(url)
print client
Service ( EchoSignDocumentService14 ) tns="http://api.echosign"
Prefixes (10)
ns0 = "http://api.echosign"
ns1 = "http://dto.api.echosign"
ns2 = "http://dto10.api.echosign"
ns3 = "http://dto11.api.echosign"
ns4 = "http://dto12.api.echosign"
ns5 = "http://dto13.api.echosign"
ns15 = "http://dto14.api.echosign"
ns16 = "http://dto7.api.echosign"
ns17 = "http://dto8.api.echosign"
ns18 = "http://dto9.api.echosign"
Ports (1):
(EchoSignDocumentService14HttpPort)
Methods (45):
...
Types (146):
ns1:CallbackInfo
ns17:WidgetCreationInfo
Trimmed for brevity, but showing the namespaces and the 2 types I'm concerned with right now.
Trying to run WCI = client.factory.create("ns17:WidgetCreationInfo") generates this error:
client.factory.create("ns17:WidgetCreationInfo")
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.macosx-10.7-intel/egg/suds/client.py", line 244, in create
suds.BuildError:
An error occured while building a instance of (ns17:WidgetCreationInfo). As a result
the object you requested could not be constructed. It is recommended
that you construct the type manually using a Suds object.
Please open a ticket with a description of this error.
Reason: Type not found: '(CallbackInfo, http://dto.api.echosign, )'
So it doesn't appear to be able to find the CallbackInfo type. Maybe its because its missing the ns there?
Again, figured it out 15 min after posting here.
suds has an option to cross-pollinate all the namespaces so they all import each others schemas. autoblend can be set in the constructor or using the set_options method.
suds.client.Client(url, autoblend=True)
Take a look in the WSDL, it seems lots of definitions in http://*.api.echosign that suds cannot fetch.
Either update your /etc/hosts to make these not well-formed domains can be reached, or save the wsdl locally, modify it, then use Client('file://...', ...) to create your suds client.

Categories