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
Related
I am new to Robot Framework and I am trying to import python custom library file named "Shop.py" saved in CustomeLibrary folder. I am getting this error in pycharm IDE.
I am getting below error on this line "Library ../CustomeLibrary/Shop.py"
Getting below error:
Unresolved library: ../CustomeLibrary/Shop.py. Error generating libspec: Initializing library 'Shop' with no arguments failed: RobotNotRunningError: Cannot access execution context.
Below is the python custom library file:
from robot.api.deco import library, keyword
from robot.libraries.BuiltIn import BuiltIn
from SeleniumLibrary import SeleniumLibrary
#library
class Shop:
# method name will be converted to keyword
def __init__(self):
self.selLib = BuiltIn().get_library_instance("SeleniumLibrary")
#keyword
def add_items_to_cart_and_checkout(self, productsList):
i = 1
productsTitles = self.selLib.get_webelements("xpath://*[#class='card-title']")
for productsTite in productsTitles:
if productsTitle.text in productsList:
self.selLib.click_button("xpath:(//*[#class='card-footer'])["+str(i)+"]/button")
i = i + 1
Can anyone help me to resolve this issue.
Other details:
python version = python 3.10.1
Robot Framework 6.0.1
pip 22.3.1
robotframework-seleniumlibrary 6.0.0
I am trying to import the python custom library file in robot framework using
"Library ../CustomeLibrary/Shop.py"
and I am getting below error:
Unresolved library: ../CustomeLibrary/Shop.py. Error generating libspec: Initializing library 'Shop' with no arguments failed: RobotNotRunningError: Cannot access execution context
I am expecting that Shop.py should get successfully imported and i should be able to us the robot custom keyword
"Add items to cart and checkout"
Similar problem is described here.
In order to obtain keyword names your __init__ is executed. Inside it you are trying to get instance of built-in library of running robotframework, but robot isn't running (check exception name).
You could replace self.selLib with property so your code could look something like that:
from robot.api.deco import library, keyword
from robot.libraries.BuiltIn import BuiltIn
from SeleniumLibrary import SeleniumLibrary
#library
class Shop:
#property
def selLib(self):
return BuiltIn().get_library_instance("SeleniumLibrary")
#keyword
def add_items_to_cart_and_checkout(self, productsList):
i = 1
productsTitles = self.selLib.get_webelements("xpath://*[#class='card-title']")
for productsTitle in productsTitles:
if productsTitle.text in productsList:
self.selLib.click_button("xpath:(//*[#class='card-footer'])["+str(i)+"]/button")
i = i + 1
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.
Trying to integrate django 1.10 application with twilio 6.0.0 and django-twilio==0.8.0
referring link
showing Error in my shell..
7 def send_twilio_message(to_number, body):
----> 8 client = twilio.rest.TwilioRestClient(
9 settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
10
AttributeError: 'module' object has no attribute 'TwilioRestClient'
Updated with the solution:
version twilio==6.0.0 (current one ) has different directory structure,so it effect importing structure Below is the updated importing structure ..
from django.conf import settings
import twilio
import twilio.rest
from twilio.rest import Client
def send_twilio_message(to_number, body):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
return client.api.account.messages.create(
body=body,
to=to_number,
from_=settings.PHONE_NUMBER
)
The tutorial you are following was written for an older version of the twilio sdk than 6.0.
You could try to look for a newer tutorial to follow, or you could try to adjust the tutorial. The migration guide might help with this.
You final option is to install an older, unsupported version of the twilio library that works with the tutorial, e.g.
pip install twilio==5.7
I am trying to include the SUDS library in a Python project through Google App Engine.
My code tries the following:
from suds.client import Client
from suds.wsse import *
And, once I've deployed on GAE, I encounter the following error:
File ".../myfile.py", line 13, in <module>
from suds.client import Client
File ".../suds/__init__.py", line 154, in <module>
import client
File ".../suds/client.py", line 25, in <module>
import suds.metrics as metrics
AttributeError: 'module' object has no attribute 'suds'
I've been looking around for a little while, and it seems like SUDS is workable with GAE. I added the fixes outlined here, but that doesn't seem to be the problem. It seems like App Engine doesn't even get to that point.
Any info or suggestions?
I'm using Python 2.7 and SUDS 0.4.
Have you tried doing a simple import suds.client? Also make sure you include the suds folder in your application as App Engine doesn't include it by default. I hope that helps.