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?
Related
I wanted to turn the discord, but it gives an error.
I found a bot on the Internet, I wanted to take it as a basis, and add various functions in the future. But I downloaded everything, inserted the token and made the first launch and an error.
link to code - https://github.com/sergree/DolboNet
the error itself -
ERROR discord.client Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\alexe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "C:\Users\alexe\Desktop\DolboNet-master\core\checking_client.py", line 13, in on_ready
await self.logout()
AttributeError: 'CheckingClient' object has no attribute 'logout'
import discord
from core.checking_client import CheckingClient
import config
from utils.tprint import log
import asyncio
log("Проверяю Discord токен...")
checking_client = CheckingClient(intents=discord.Intents.none())
login_successful = False
try:
checking_client.run(config.token)
login_successful = True
except discord.errors.LoginFailure:
log("НЕВЕРНЫЙ DISCORD ТОКЕН! Необходимо отредактировать файл config.py!")
if login_successful:
log("Discord токен проверен.")
asyncio.set_event_loop(asyncio.new_event_loop())
from core.main_client import MainClient
intents = discord.Intents.none()
intents.guilds = True
intents.guild_messages = True
intents.emojis = True
main_client = MainClient(intents=intents)
main_client.run(config.token)
Thanks for the help!
I tried to update my videos publishing date via youtube api bu i get TypeError. I didn't understand why i get this error. I thought it may be because of date format so i tried to datetime instead of "2020-2-5T20:00:00.00+03:00" but outcomes didn't changed. Can you help me?
Here is my code:
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret.json"
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
date = datetime.datetime(2020, 2, 5, 20, 00)
request = youtube.videos().update(
body={
"id": 'D5sSw6Xqu34',
"status": {
"privacyStatus": "private",
"publishAt": "2020-2-5T20:00:00.00+03:00"
}
}
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
Here is error:
Traceback (most recent call last):
File "C:/Users/erkan/Desktop/uppo/tekli.py", line 46, in <module>
main()
File "C:/Users/erkan/Desktop/uppo/tekli.py", line 36, in main
"publishAt": '2020-2-5T20:00:00.00+03:00',
File "C:\Users\erkan\Desktop\uppo\venv\lib\site-packages\googleapiclient\discovery.py", line 731, in method
raise TypeError('Missing required parameter "%s"' % name)
TypeError: Missing required parameter "part"
Process finished with exit code 1
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)
I am in the process of trying to use flask-sqlalchemy, and I have followed numerous examples in the documentation of how to get the Flask application setup. However, I am not able to get the app context for some reason. I am currently using the app.app_context().push() method. Is there some other way to get this to work? What am I doing wrong? Any help would be appreciated.
Currently running:
Python==3.6.3
Flask==0.12.2
Flask-Compress==1.4.0
Flask-SQLAlchemy==2.3.2
model.py
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import relationship
db = SQLAlchemy()
class Property(db.Model):
__tablename__ = 'vt_property'
id = db.Column(db.BigInteger, primary_key=True)
name = db.Column(db.String(32))
value = db.Column(db.LargeBinary)
client_tag = db.Column(db.String(16))
index.py
from flask import Flask, jsonify, request
from flask_compress import Compress
from database.model import *
from manager.some_util import some_user, some_url, some_pass
# App config.
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
Compress(app)
app.secret_key = secret_key
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://connection_string'
db.init_app(app)
app.app_context().push()
some_util.py
from database.model import Property
from helpers.util import secret_key
def load_some_config():
from secure.secure import read_encrypted_text
some_configs = Property.query.filter(Property.name.contains('MANAGER')).all()
some_url = ''
some_user = ''
some_pass = ''
for c in some_configs:
if 'URL' in c.name:
some_url = c.value.decode('utf-8')
if 'USER' in c.name:
some_user = c.value.decode('utf-8')
if 'PASS' in c.name:
some_pass = read_encrypted_text(c.value).decode('utf-8')
return some_url, some_user, some_pass
When I try to run my API, I get this error:
*/venv/bin/python */src/api/index.py
Traceback (most recent call last):
File "*/venv/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 988, in __call__
return self.registry[key]
KeyError: <greenlet.greenlet object at 0xXXXXXXXX>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "*/src/api/index.py", line 16, in <module>
from manager.some_util import some_user, some_url, some_pass
File "*/src/manager/some_util.py", line 23, in <module>
some_url, some_user, some_pass = load_some_config()
File "*/src/manager/some_util.py", line 9, in load_some_config
some_configs = Property.query.filter(Property.name.contains(‘MANAGER’)).all()
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 514, in __get__
return type.query_class(mapper, session=self.sa.session())
File "*/venv/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 78, in __call__
return self.registry()
File "*/venv/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 990, in __call__
return self.registry.setdefault(key, self.createfunc())
File "*/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2882, in __call__
return self.class_(**local_kw)
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 141, in __init__
self.app = app = db.get_app()
File "*/venv/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 912, in get_app
'No application found. Either work inside a view function or push'
RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
To execute some code within the Flask app context, the most simple way is doing this:
with self.app.app_context():
# ... your code here ...
Note that app is your Flask application object. The variable name might be different in your case.
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 :(