I'm trying to read a bson file this is my code:
import bson
with open("D:/rl env/chat_log.bson",'rb') as f:
datas = bson.decode_all(f.read())
note that "D:/rl env/chat_log.bson" is my file path.
i got below error:
AttributeError: module 'bson' has no attribute 'decode_all'
I must mention that I didn't get any error when I ran this code in google colab.
Have you tried to use the loads method
with open("D:/rl env/chat_log.bson",'r') as f:
datas = bson.loads(f.read())
Related
The following code worked without a problem before.
import pyowm
owm = pyowm.OWM(owm_api_key)
manager = owm.weather_manager()
But now it instead outputs the error AttributeError: 'OWM25' object has no attribute 'weather_manager'
Following the code recipe in the docs, it suggests that you should do the following:
from pyowm.owm import OWM
owm = OWM(owm_api_key)
manager = owm.weather_manager()
But that just gives the error: ModuleNotFoundError: No module named 'pyowm.owm'
Considering that my code worked previously, I'm guessing that it is just some update but I can't find the right way to do it.
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 can't access the helpers of elasticsearch while trying to push data in bulk mode. Package installed :
pip freeze
elasticsearch==5.3.0
When in my code I try to call this method :
import elasticsearch
client = elasticsearch.Elasticsearch([config['ES']['host']],
connection_class=elasticsearch.RequestsHttpConnection,
http_auth=(config['ES']['userName'], config['ES']['password']),
port=int(config['ES']['hostPort']),
use_ssl=True,
verify_certs=False)
elasticsearch.helpers.bulk(client, body)
I got the following error :
AttributeError: module 'elasticsearch' has no attribute 'helpers'
I'm using Python 3.5.1 and I have no problem reading data from my es cluster (without the use of helpers of course)
As #Jon Clements♦ correctly said,
import elasticsearch.helpers
Is the correct way to import (therefore also the following works)
from elasticsearch.helpers import scan
Enjoy
I cannot seem to create and attach a file to an item in podio using the pypodio client, which is the python wrapper for PODIO's API. I am trying to get the file id but keep on getting the error. I am using Python 3.6.0
My code is
`path = os.getcwd()`
`filename="system_information"`
`filepath = path + "\\system_information.txt"`
`filedata=open(filepath)`
uploading_response = pcbapp.Files.create(filename,filedata)
I get an error shown below,
File "c:\users\nipun.arora\src\podio-py\pypodio2\encode.py", line 317, in get_headers
boundary = urllib.quote_plus(boundary)
AttributeError: module 'urllib' has no attribute 'quote_plus'
That's might be because there is no urllib.quote_plus in python3. Can you try running same code in python2?
I installed everything as it says on the FlickrAPI homepage but when I try to run:
import flickrapi
api_key = '1a4c975fa83048436a2086bcab7d2290'
api_password = '5e069eae20e60297'
flickrclient = flickrapi.FlickAPI(api_key, api_password)
favourites = flickrClient.favorites_getPublicList(user_id='userid')
photos = flickr.photos_search(user_id='73509078#N00', per_page='10')
sets = flickr.photosets_getList(user_id='73509078#N00')
for photo in favourites.photos[0].photo:
print photo['title']
I get this message from the command prompt:
C:\Users\Desktop>python api.py
Traceback (most recent call last):
File "api.py", line 4, in <module>
flickrclient = flickrapi.FlickAPI(api_key, api_password)
AttributeError: 'module' object has no attribute 'FlickAPI'
Any ideas?? I have tried almost everything
FlickAPI is not the same as FlickrAPI. You're missing an r.
The file C:\Users\XXXXXX\Desktop\FLICKR API\flickrapi.py is not part of the flickrapi package. Please rename it, it is masking the real library. Right now it is being imported instead of the installed package.
The flickrapi package itself consists of a directory with a __init__.py file inside of it. Printing flickrapi.__file__ should result in a path ending in flickrapi\__init__.py.
In your "flickrclient = flickrapi.FlickAPI" line, you're missing an 'r' in FlickAPI.
Also, on the next line, your *"user_id='userid'"* argument needs an actual user ID, such as '999999#N99'
Hopefully you found that & got this working a few months ago! :)