Is there a way to specify the search type when using pyelasticsearch? There's nothing in the documentation for 'scan', 'scroll', 'query_and_fetch', etc. Running the following code:
from pyelasticsearch import ElasticSearch
es = ElasticSearch(...)
query = {
"query" : {
"term" : { "DocContent" : "the" }
}
}
x = es.search(query, index='main', search_type='scan', scroll='1m')
Produces the following error:
E:\query>python query.py
Traceback (most recent call last):
File "query.py", line 11, in <module>
x = es.search(query, index='main', scroll='1m', document_type='scan')
File "C:\Python27\lib\site-packages\pyelasticsearch-0.7.1-py2.7.egg\pyelasticsearch\client.py", line 96, in decorate
return func(*args, query_params=query_params, **kwargs)
File "C:\Python27\lib\site-packages\pyelasticsearch-0.7.1-py2.7.egg\pyelasticsearch\client.py", line 591, in search
return self._search_or_count('_search', query, **kwargs)
TypeError: _search_or_count() got an unexpected keyword argument 'search_type'
Look like you got an old pyleasticsearch lib, update or else :(
Related
I am trying to set a delegate with gnosis safe.
The following code shows that we need to send a POST request with python3 to register a delegate with gnosis safe:
https://safe-docs.dev.gnosisdev.com/safe/docs/tutorial_tx_service_set_delegate/
I have put the following code together in a script however i cannot get it to work
import requests
import time
import sha3
SAFE_ADDRESS = '*'
OWNER_PRIVATE_KEY = '*'
DELEGATE_ADDRESS = '*'
TX_SERVICE_BASE_URL = 'https://safe-transaction.rinkeby.gnosis.io'
totp = int(time.time()) // 3600
hash_to_sign = sha3.keccak_256(text=DELEGATE_ADDRESS + str(totp))
account = Account.from_key(OWNER_PRIVATE_KEY)
signature = account.signHash(hash_to_sign)
add_payload = {
"safe": SAFE_ADDRESS,
"delegate": DELEGATE_ADDRESS,
"signature": signature.signature.hex(),
"label": "My new delegate2"
}
print(list_response.text)
print(list_response.status_code)
when i run it i get this error:
Traceback (most recent call last):
File "test.py", line 11, in <module>
hash_to_sign = sha3.keccak_256(text=DELEGATE_ADDRESS + str(totp))
TypeError: 'text' is an invalid keyword argument for sha3_224()
i've also tried to change keccak to 512 but its not working.
How can i fix it?
For mlflow, when I use get_model_version(model_name, model_version) method it works fine,
but get_latest_versions method fails as shown below. The same model that I am able to get by its version number also has assigned stage 'Production' but I can't get it by specifying this stage. On my client side I have mlflow 1.24.0 (tried 1.23.0 and 1.23.1 too) under Python 3.9.7 (tried 3.8.8 too) on Windows 10. I believe the server uses mlflow 1.18.
import mlflow
from mlflow.tracking import MlflowClient
...
mlflow.set_tracking_uri('https://fs-mlflow-dev.whatever.whatever.com/')
...
client = MlflowClient()
model_stage='Production'
_vers = client.get_latest_versions(model_name, [model_stage])
Traceback (most recent call last):
File "C:\Users\926304897\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\926304897\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\test_decision.py", line 92, in <module>
main(confidence_interval=conf_int)
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\test_decision.py", line 54, in main
cdm.load_model( model_stage=LOAD_STAGE)#model_version=27 )
File "C:\Users\926304897\Documents\GitHub\CreditModeling\src\models\decision_model.py", line 1128, in load_model
_vers = client.get_latest_versions(model_name, [model_stage])
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\tracking\client.py", line 2048, in get_latest_versions
return self._get_registry_client().get_latest_versions(name, stages)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\tracking\_model_registry\client.py", line 149, in get_latest_v
ersions
return self.store.get_latest_versions(name, stages)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\store\model_registry\rest_store.py", line 197, in get_latest_v
ersions
response_proto = self._call_endpoint(GetLatestVersions, req_body, call_all_endpoints=True)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\store\model_registry\rest_store.py", line 61, in _call_endpoin
t
return call_endpoints(self.get_host_creds(), endpoints, json_body, response_proto)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 251, in call_endpoints
return call_endpoint(host_creds, endpoint, method, json_body, response_proto)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 240, in call_endpoint
response = verify_rest_response(response, endpoint)
File "C:\Users\926304897\AppData\Local\JetBrains\PyCharmCE2021.3\demo\PyCharmLearningProject\venv\lib\site-packages\mlflow\utils\rest_utils.py", line 175, in verify_rest_response
raise MlflowException("%s. Response body: '%s'" % (base_msg, response.text))
mlflow.exceptions.MlflowException: API request to endpoint /api/2.0/mlflow/registered-models/get-latest-versions failed with error code 405 != 200. Response body: '<!DOCTYPE HTML PUBLIC "
-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
I had this same problem running MLFlow client as 1.23.1 and noticed the server was at 1.14. I upgraded the server to 1.26 and the problem went away.
I have a model registered as TestModel (v1) and flagged as Production.
I have an S3 back-end with credentials set as ENV vars along with the following:
MLFLOW_ARTIFACT_LOCATION
MLFLOW_S3_ENDPOINT_URL
MLFLOW_TRACKING_URI
import mlflow
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/1") # Works
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/Production") # Works
model = mlflow.pyfunc.load_model(model_uri="models:/TestModel/Staging") # Fails as expected with:
# mlflow.exceptions.MlflowException: No versions of model with name 'TestModel' and stage 'Staging' found
I am trying to migrate to Django 2.0 from 1.11 but some unit tests related to django-autocomplete-light (3.5.1) have started failing with a TypeError after calling self.client.get() from TestCase class. (__init__() takes 1 positional argument but 2 were given)
Some suggestions I found stated that missing as_view() in the URL view could be the issue but it is already there. I also changed the MIDDLEWARE_CLASSES variable to MIDDLEWARE in the settings.
test.py
from django.urls import reverse
from django.test import TestCase
from django.contrib.auth.models import User
class AutocompleteTestCase(TestCase):
def setUp(self):
self.admin_cred = {
'username': 'test',
'password': 'test',
}
self.user = User.objects.create_superuser('test', 'test#test.com', self.admin_cred['password'])
def query_autocomplete_view(self, url_name, query=None):
data = {}
if query:
data['q'] = query
self.client.force_login(self.user)
response_json = self.client.get(reverse(url_name), data=data).json()
return response_json.get('results')
Error Traceback
Traceback (most recent call last):
File "/home/circleci/project/test/apps/dataadmin/tests/test_autocomplete_views.py", line 131, in test_dataadmin_field_autocomplete
results = self.query_autocomplete_view('admin:dataadmin_autocomplete_dataadminfield', query='test')
File "/home/circleci/project/dataadmin/common/test_utils.py", line 23, in query_autocomplete_view
response_json = self.client.get(reverse(url_name), data=data).json()
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/test/client.py", line 517, in get
response = super().get(path, data=data, secure=secure, **extra)
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/test/client.py", line 332, in get
return self.generic('GET', path, secure=secure, **r)
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/test/client.py", line 404, in generic
return self.request(**r)
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/test/client.py", line 467, in request
response = self.handler(environ)
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/test/client.py", line 125, in __call__
self.load_middleware()
File "/home/circleci/project/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware
mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given
The error seems to happen after loading the middleware, but I couldn't identify any issues with the middleware setup.
settings.py
MIDDLEWARE = (
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'allow_cidr.middleware.AllowCIDRMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django_auditor.middleware.AuditorMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
)
AdminApp is using django.contrib.admin.AdminSite. It customizes the base admin app. The function returns the list of URL patterns.
admin.py
class DataAdminApp(AdminApp):
def get_urls(self):
return [
url(
r'^dataadmin/autocomplete/dataadminfield/$',
self.admin_view(DataAdminFieldAutocomplete.as_view()),
name="dataadmin_autocomplete_dataadminfield"
)
]
Code:
...
#client.event
async def on_message(message):
if 'e_lastprism' in message.content.lower():
await message.delete()
await message.guild.create_custom_emoji(name = ('lastprism'), image = (b'D:\Desktop\diskord BOT\emoji\lastprism.jpg'))
...
After entering, an error emerges:
discord.errors.InvalidArgument: Unsupported image type given
Full Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 251, in on_message
await message.guild.create_custom_emoji(name = ("lastprism"), image = (b'D:\Desktop\diskord BOT\emoji\lastprism.jpg'))
File "C:\Program Files\Python37\lib\site-packages\discord\guild.py", line 1504, in create_custom_emoji
img = utils._bytes_to_base64_data(image)
File "C:\Program Files\Python37\lib\site-packages\discord\utils.py", line 299, in _bytes_to_base64_data
mime = _get_mime_type_for_image(data)
File "C:\Program Files\Python37\lib\site-packages\discord\utils.py", line 295, in _get_mime_type_for_image
raise InvalidArgument('Unsupported image type given')
discord.errors.InvalidArgument: Unsupported image type given
How can I fix this?
I have not came across this one before but try using .jpg or .jpeg. as it says the wrong image type.
I fix my code with:
with open("D:\Desktop\diskord BOT\emoji\lastprism.png", "rb") as img:
img_byte = img.read()
await message.guild.create_custom_emoji(name = ("lastprism"), image = img_byte)
Using a python script for posting articles on WordPress website. That was working fine till few days. Now , its returning error related to 409 conflict.
Unable to track the reason as there is no change in code from my side.
Traceback (most recent call last):
File "/home/vikas/anaconda3/lib/python3.7/site-packages/wordpress_xmlrpc/base.py", line 24, in __init__
self.supported_methods = self.server.mt.supportedMethods()
File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1187, in single_request
dict(resp.getheaders())
xmlrpc.client.ProtocolError: <ProtocolError for www.indiandefencenews.co.in/xmlrpc.php: 409 Conflict>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "t.py", line 16, in <module>
client = Client('https://www.indiandefencenews.co.in/xmlrpc.php','user','password')
File "/home/vikas/anaconda3/lib/python3.7/site-packages/wordpress_xmlrpc/base.py", line 27, in __init__
raise ServerConnectionError(repr(e))
wordpress_xmlrpc.exceptions.ServerConnectionError: <ProtocolError for www.indiandefencenews.co.in/xmlrpc.php: 409 Conflict>
My Code for the same is :
import urllib.request
import random
import csv
import os
import re
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
client = Client('https://www.website.com/xmlrpc.php','User','password')
# prepare metadata
data = {
'name': 'picture.jpg',
'type': 'image/jpeg', # mimetype
}
with open(filename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
attachment_id = response['id']
post = WordPressPost()
post.title = title
post.content = text
post.post_status = 'publish'
post.thumbnail = attachment_id
post.id = client.call(posts.NewPost(post))
PID=post.id
print ('Success')
strn=str(num)
url = url.replace(strn,'')
print (strn)
strn=int(num)+1
url=url+str(strn)
print (url)