I am trying to upload JSON file into a new container on Azure blob Storage account.
I use Microsoft quick guide
Currently my code looks like this:
>import os, uuid
>from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
>connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
So far It's works OK but when I add this line
>blob_service_client = BlobServiceClient.from_connection_string(connect_str)
I get an error message:
>(base) "`my file path`"
Traceback (most recent call last):
File "`my file path`", line 14, in <module>
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
File `".../anaconda3/lib/python3.8/site-packages/azure/storage/blob/_blob_service_client.py"`, line 174, in from_connection_string
account_url, secondary, credential = parse_connection_str(conn_str, credential, 'blob')
File `".../anaconda3/lib/python3.8/site-packages/azure/storage/blob/_shared/base_client.py"`, line 363, in parse_connection_str
conn_str = conn_str.rstrip(";")
AttributeError: 'NoneType' object has no attribute 'rstrip'
I had wrote the same code on my PC and about a month ago I moved to Mac OS. I thought I did all the relevant adjustments, but apparently not.
Since this mac is completely new I think I missing a few packages or maybe hav the wrong versions of the packages.
I am attaching pip list:
azure-common 1.1.27
azure-core 1.12.0
azure-nspkg 3.0.2
azure-storage 0.36.0
azure-storage-blob 12.9.0
Thank you!
Your environment variable is probably not found.
Try this code
connect_str = os.environ['AZURE_STORAGE_CONNECTION_STRING']
It should raise a KeyError or return None.
I think you should be sure the variable is really read or that its value is not None.
Related
import boto3
import json
import time
client = boto3.client('elbv2')
desired_capacity=8
client.set_desired_capacity(
AutoScalingGroupName='Test-Web',
DesiredCapacity=desired_capacity,
HonorCooldown=True)
and
boto3==1.7.1
When I run this script I get a
File "deploy_staging_web.py", line 6, in <module>
client.set_desired_capacity(
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 601, in __getattr__
self.__class__.__name__, item)
AttributeError: 'ElasticLoadBalancingv2' object has no attribute 'set_desired_capacity'
I intended to use python to scale aws instances up and down.
I'm not inside any virtual environment at the moment.
why is it being thrown, and how do I get across it?
It is even mentioned here on the official documentation : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.set_desired_capacity
The official document is for the latest version, not your too old version. Upgrade your boto3 package to the latest. The most recent version is 1.9.243.
The problem turns out to be a silly one.
boto3 has moved around the various functions.
set_desired_capacity is no longer part of 'elbv2' .
It is part of 'autoscaling' https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.set_desired_capacity
While 'describe_target_health' is still part of the former https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html?highlight=elb#ElasticLoadBalancingv2.Client.describe_target_health.
Updating
client = boto3.client('elbv2')
to
client = boto3.client('autoscaling')
has solved my problem.
I developed a Python 2.7 app using the smartsheet SDK and it works fine on y machine. Then I bundle it into an app via PyInstaller and I get this error when I run it:
DEBUG:smartsheet.smartsheet:try loading api class Home
DEBUG:smartsheet.smartsheet:try loading model class Home
DEBUG:smartsheet.smartsheet:ImportError! Cound not load api or model
class Home Exception in Tkinter callback Traceback (most recent call
last): File "lib-tk/Tkinter.py", line 1536, in __call__ File
"pacers.py", line 166, in log_processing File "pacers.py", line 57,
in new_sheet AttributeError: 'str' object has no attribute
'create_sheet'
EDIT 1:
It's this AttributeError that I can't get my head around. I'm able to create other smartsheet objects before this with no problem. And running the source code doesn't present a problem. Any ideas?
It works from source just fine! -->
DEBUG:smartsheet.smartsheet:try loading api class Home
DEBUG:smartsheet.smartsheet:loaded instance of api class Home
DEBUG:smartsheet.models.column:deleting index from obj (filter: create_sheet)
DEBUG:smartsheet.models.column:deleting locked from obj (filter: create_sheet)
Edit 2:
Turns out PyInstaller wasn't importing all of the module properly, had to explicitly import objects, e.g. smartsheet.Home
I had a similar issue,
To resolve I used from smartsheet import Smartsheet instead of import smartsheet
I am currently working on authenticating my users. I checked out this blog - RESTful Authentication with Flask - and followed its steps to produce a piece of code I believed would serve my purpose. I wanted to use the Timed Json Serializer class for my particular use case. Below, I am creating an object of that class, generating a token and trying to load the data with it.
from itsdangerous import TimedJSONWebSignatureSerializer
user_id = 'fake1'
s = TimedJSONWebSignatureSerializer(parser_app.config['SECRET_KEY'], expires_in=3600)
token = s.dumps({'user_id' : user_id})
print(token)
print (s.loads(token))
I get the following callback:
Traceback (most recent call last):
eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ2ODI3MjU3MSwiaWF0IjoxNDY4MjY4OTcxfQ.eyJ1c2VyX2lkIjoiZmFrZTEifQ.Ch8y6BDMIIBdIGM0lmjdAimINvP3PnUmBpOp-jDW18w
File "C:/Users/vaibhav/PycharmProjects/Coding/Coding.py", line 6, in <module>
print (s.loads(token))
File "C:\Users\vaibhav\Anaconda\lib\site-packages\itsdangerous.py", line 798, in loads
self, s, salt, return_header=True)
File "C:\Users\vaibhav\Anaconda\lib\site-packages\itsdangerous.py", line 752, in loads
self.make_signer(salt, self.algorithm).unsign(want_bytes(s)),
File "C:\Users\vaibhav\Anaconda\lib\site-packages\itsdangerous.py", line 377, in unsign
payload=value)
itsdangerous.BadSignature: Signature 'Ch8y6BDMIIBdIGM0lmjdAimINvP3PnUmBpOp-jDW18w' does not match
I have just created the token with an expiry of an hour and it gives me a BadSignature which indicates that the token does not match. The desired output would be:
{"user_id" : "fake1"}
Please help me out.
I ended up having to uninstall and reinstall the package itsdangerous with pip. The statements used were:
pip uninstall itsdangerous
followed by:
pip install itsdangerous
Apparently, the file had been corrupted somehow causing it not to work properly.
I am trying to use the Google Drive API to download publicly available files however whenever I try to proceed I get an import error.
For reference, I have successfully set up the OAuth2 such that I have a client id as well as a client secret , and a redirect url however when I try setting it up I get an error saying the object has no attribute urllen
>>> from apiclient.discovery import build
>>> from oauth2client.client import OAuth2WebServerFlow
>>> flow = OAuth2WebServerFlow(client_id='not_showing_client_id', client_secret='not_showing_secret_id', scope='https://www.googleapis.com/auth/drive', redirect_uri='https://www.example.com/oauth2callback')
>>> auth_uri = flow.step1_get_authorize_url()
>>> code = '4/E4h7XYQXXbVNMfOqA5QzF-7gGMagHSWm__KIH6GSSU4#'
>>> credentials = flow.step2_exchange(code)
And then I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line
137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line
1980, in step2_exchange
body = urllib.parse.urlencode(post_data)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute
'urlencode'
Any help would be appreciated, also would someone mind enlightening me as to how I instantiate a drive_file because according to https://developers.google.com/drive/web/manage-downloads, I need to instantiate one and I am unsure of how to do so.
Edit: So I figured out why I was getting the error I got before. If anyone else is having the same problem then try running.
sudo pip install -I google-api-python-client==1.3.2
However I am still unclear about the drive instance so any help with that would be appreciated.
Edit 2: Okay so I figured out the answer to my whole question. The drive instance is just the metadata which results when we use the API to search for a file based on its id
So as I said in my edits try the sudo pip install and a file instance is just a dictionary of meta data.
from a ubuntu machine I use beatbox python package to connect to SF and get the objects descriptions
but can't manage to get access to the ForecastingItems object.
I checked my privileges to access the object and I have full access as admin
the script I'm using is bellow, when I changed the object ForecastingItem with Account it does pull all the object fields.
#!/usr/bin/python
# coding=utf8
import beatbox
import pprint
import sys
import os
import datetime
sf_service = beatbox.PythonClient()
sf_service.login('email#hotmail.com', 'password$numbersletter')
desc_obj = sf_service.describeSObjects('ForecastingItem')
forcat_item = desc_obj[0]
forItem_fields = forcat_item.fields
for sf_field_key, sf_field_value in forItem_fields.items():
print sf_field_key
I heard that I should upgrade beatbox to something more than the version 21 to be able to access the ForecastingItem object so I tried apt-get update upgrade beatbox, but I still get the error :
Traceback (most recent call last):
File "./fields_associated_with_an_object.py", line 14, in <module>
desc_obj = sf_service.describeSObjects('ForecastingItem')
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/python_client.py", line 131, in describeSObjects
res = BaseClient.describeSObjects(self, sObjectTypes)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 108, in describeSObjects
return DescribeSObjectsRequest(self.__serverUrl, self.sessionId, sObjectTypes).post(self.__conn)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 332, in post
raise SoapFaultError(faultCode, faultString)
beatbox._beatbox.SoapFaultError: 'INVALID_TYPE' "INVALID_TYPE: sObject type 'ForecastingItem' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."
Thanks in advance!