An error in signature when pushing using pygi2 - python

I'm facing problem when pushing using pygit2 v0.21.3 .
here is my code :
import pygit2 as git
repo = git.Repository("path/to/my/repo.git") # just for testing,it will not be local
for rem in repo.remotes:
rem.push_url = rem.url
rem.credentials = git.UserPass("user","passowrd")
sig = git.Signature("user","user#example.com")
rem.push('refs/heads/master',signature=sig)
# in v0.22.0 it will be like below
# rem.push(['refs/heads/master'],signature=sig)
But,I always received this message :
Traceback (most recent call last):
File "C:\test.py", line 9, in <module>
rem.push('refs/heads/master',signature=sig)
File "C:\Python34\lib\site-packages\pygit2-0.21.3-py3.4-win32.egg\pygit2\remote.py",line 353, in push
err = C.git_push_update_tips(push, ptr, to_bytes(message))
TypeError: initializer for ctype 'git_signature *' must be a cdata pointer, not bytes
When I tried it with version 0.22.0 it didn't raise an error, but push operation also didn't work.
Note: I think the problem with signature parameter, because when I pass None It works fine with default signature .
Thanks.

I had updated pygit2 to v0.22.1, libgit2 to v0.22.3 , it fixed the problem.

Related

viewer error when running the stokesCavity.py example

Running Manjaro stable with python-3.9 and python-fipy-3.4.2.1-1.
Just got started with FiPy, ultimately interested in writing single and two-phase flow code. Naturally I tried to run examples/flow/stokesCavity.py (stripped down from all rst text) with: python stokesCavity.py and it throws the following error:
Traceback (most recent call last):
File "/home/zbinkz/HGST/Projects/Python/fipy/examples/flow/stokesCavity.py", line 117, in <module>
viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
File "/usr/lib/python3.9/site-packages/fipy/viewers/__init__.py", line 130, in Viewer
raise ImportError("Failed to import a viewer: %s" % str(errors))
ImportError: Failed to import a viewer: ["matplotlib: True is not a valid value for orientation; supported values are None, 'vertical', 'horizontal'", "mayavi: No module named 'enthought'"]
I tinkered with different values for FIPY_VIEWER in the viewer command at line 117 reported above but still get the same error. At this very early stage with FiPy I'm clueless, anybody know how to fix this?
Thanks :)
In this line, change
... viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
... xmin=0., xmax=1., ymin=0., ymax=1., colorbar=True)
to
... viewer = Viewer(vars=(pressure, xVelocity, yVelocity, velocity),
... xmin=0., xmax=1., ymin=0., ymax=1., colorbar='vertical')
I've filed a ticket to correct this.

python 3 'function' object is not iterable

I am new to python and I am trying to create a chat server in python using socket. In my server i want to encrypt and decrypt the message sended from the client to the sever.I am trying to create a key from the server then send it to the client but i got this error: "'function' object is not iterable" . I am following this guide : https://riptutorial.com/python/topic/8710/sockets-and-message-encryption-decryption-between-client-and-server.
Here are the code that generate the error:
key_128 = os.urandom(16)
#encrypt CTR MODE session key
en = AES.new(key_128,AES.MODE_CTR,counter = lambda:key_128)
encrypto = en.encrypt(key_128)
and this is the error :
Traceback (most recent call last):
File "test.py", line 4, in <module>
en = AES.new(key_128,AES.MODE_CTR,counter = lambda:key_128)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\AES.py", line 232, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\Crypto\Cipher\_mode_ctr.py", line 366, in _create_ctr_cipher
_counter = dict(counter)
TypeError: 'function' object is not iterable
I tried to run this guide on python 2.7 and it run ok. But i run on python 3 it has error. Can some one explain why and help me fix this?
Update :
I am using pycryptodome instead of Pycrypto because i cant install Pycrypto in my pc.
I did some researches how to fix this. There is the link that said the error is caused by conflict between python-crypto in lib and local/lib ... But i dont think it is. Here is the link https://github.com/nccgroup/Winpayloads/issues/21
Per the documentation:
counter : (object) – Instance of Crypto.Util.Counter, which allows full customization of the counter block. This parameter is incompatible to both nonce and initial_value.
counter in this context is an anonymous function (a lambda), but not an instance of Crypto.Util.Counter. Given key_128 = os.urandom(16) - key_128 is a string.

Pl\Python: issues when importing module

I have successfully setup plpyton3u extension in Postgresql 10 (64 bit) on my windows 10 (64 bit) machine. However, when i try to make a http request by calling requests module I am getting attribute error AttributeError: 'module' object has no attribute 'get' . Here is the code that I am using
CREATE OR REPLACE FUNCTION from_url(
-- The URL to download.
IN url text,
-- Should any errors (like HTTP transport errors)
-- throw an exception or simply return default_response
IN should_throw boolean DEFAULT true,
-- The default response if any errors are found.
-- Only used when should_throw is set to true
IN default_response text DEFAULT E''
)
RETURNS text
AS $$
# We will use traceback so we get decent error reporting.
import requests
import traceback
# Either throws an error or returns the defeault response
# depending on the should_throw parameter of the from_url() function
def on_error():
if should_throw:
# plpy.error() throws an exception which stops the current transaction
plpy.error("Error downloading '{0}'\n {1}".format(url, traceback.format_exc()))
else:
return default_response
try:
response = requests.get(url)
return response.data
except:
# Log and re-throw the error or return the default response
return on_error()
$$ LANGUAGE plpython3u VOLATILE;
select from_url(<SOME_DATA_FETCHING_URL>);
Where SOME_DATA_FETCHING_URL is the url of the server serving the data. When I run this code it throws following error
ERROR: plpy.Error: Error downloading SOME_DATA_FETCHING_URL
Traceback (most recent call last):
File "", line 16, in __plpython_procedure_from_url_24640
AttributeError: 'module' object has no attribute 'get'
CONTEXT: Traceback (most recent call last):
PL/Python function "from_url", line 19, in
return on_error()
PL/Python function "from_url", line 11, in on_error
plpy.error("Error downloading '{0}'\n {1}".format(url, traceback.format_exc()))
PL/Python function "from_url"
SQL state: XX000
my PYTHONPATH is set to C:\Python34\;C:\Python34\Scripts;C:\Python34\Lib;
I checked on python command prompt, I am able to import requests and run the get command successfully.
Am I missing any settings in PostGRESQL? which will allow me to run this code successfully?
(In case anyone else stumbles on this question) I had a similar problem, in my case it turned out to be caused by inadequate access permissions for user 'postgres' to the directory containing my Python modules. One thing I have learnt is that to check a PL/Python problem using the Python command prompt, it's always necessary to run it as the same user as the Postgres server (in my case, 'postgres')

predictionio seems to be misreading my arguments

I am using python to import data onto a server running predictionio.
I am using the following code to set up the EventClient:
import predictionio
client = predictionio.EventClient(
access_key='285',
url='http://localhost:7070',
threads=5,
qsize=500)
client.create_event(
event="rate",
entity_type="user",
entity_id="Bob",
target_entity_type="item",
target_entity_id="Fred",
properties= { "rating" : 5.0 }
)
However I keep getting the following message:
python imp.py
Traceback (most recent call last):
File "imp.py", line 6, in <module>
qsize=500)
File "C:\...\predictioni
"It seems like you are specifying an app_id. It is deprecate
DeprecationWarning: It seems like you are specifying an app_id.
ss_key instead. Or, you may use an earlier version of this sdk.
I'm clearly not specifying an app id, as I'm passing the client a named argument: "access_key". Removing the qsizeargument does nothing, the error just gets blamed on the line above, and so on. I can't find anything in the documentation and it's probably because I'm so new to all of this that I can't find out where I'm going wrong.
All of the tutorials I have been looking at create EventClients in this way and it works no problem:
http://predictionio.incubator.apache.org/datacollection/eventapi/
Any help would be greatly appreciated. Thanks.
access_key must be greater than 8 characters long.
Source code
class EventClient(BaseClient):
def __init__(self, access_key,
url="http://localhost:7070",
threads=1, qsize=0, timeout=5, channel=None):
assert type(access_key) is str, ("access_key must be string. "
"Notice that app_id has been deprecated in Prediction.IO 0.8.2. "
"Please use access_key instead.")
super(EventClient, self).__init__(url, threads, qsize, timeout)
# SEE HERE...
if len(access_key) <= 8:
raise DeprecationWarning(
"It seems like you are specifying an app_id. It is deprecated in "
"Prediction.IO 0.8.2. Please use access_key instead. Or, "
"you may use an earlier version of this sdk.")
For example
>>> client = predictionio.EventClient(access_key='12345678')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/env/py2/lib/python2.7/site-packages/predictionio/__init__.py", line 178, in __init__
"It seems like you are specifying an app_id. It is deprecated in "
DeprecationWarning: It seems like you are specifying an app_id. It is deprecated in Prediction.IO 0.8.2. Please use access_key instead. Or, you may use an earlier version of this sdk.
>>> client = predictionio.EventClient(access_key='123456789')
>>>

boto does not like EMR BootstrapAction paramater

I'm trying to launch AWS EMR cluster using boto library, everything works well.
Because of that I need to install required python libraries, tried to add bootstrap action step using boto.emr.bootstrap_action
But It gives error below;
Traceback (most recent call last):
File "run_on_emr_cluster.py", line 46, in <module>
steps=[step])
File "/usr/local/lib/python2.7/dist-packages/boto/emr/connection.py", line 552, in run_jobflow
bootstrap_action_args = [self._build_bootstrap_action_args(bootstrap_action) for bootstrap_action in bootstrap_actions]
File "/usr/local/lib/python2.7/dist-packages/boto/emr/connection.py", line 623, in _build_bootstrap_action_args
bootstrap_action_params['ScriptBootstrapAction.Path'] = bootstrap_action.path AttributeError: 'str' object has no attribute 'path'
Code below;
from boto.emr.connection import EmrConnection
conn = EmrConnection('...', '...')
from boto.emr.step import StreamingStep
step = StreamingStep(name='mapper1',
mapper='s3://xxx/mapper1.py',
reducer='s3://xxx/reducer1.py',
input='s3://xxx/input/',
output='s3://xxx/output/')
from boto.emr.bootstrap_action import BootstrapAction
bootstrap_action = BootstrapAction(name='install related packages',path="s3://xxx/bootstrap.sh", bootstrap_action_args=None)
job = conn.run_jobflow(name='emr_test',
log_uri='s3://xxx/logs',
master_instance_type='m1.small',
slave_instance_type='m1.small',
num_instances=1,
action_on_failure='TERMINATE_JOB_FLOW',
keep_alive=False,
bootstrap_actions='[bootstrap_action]',
steps=[step])
What's the proper way of passing bootstrap arguments?
You are passing the bootstrap_actions argument as a literal string rather than as a list containing the BootstrapAction object you just created. Try this:
job = conn.run_jobflow(name='emr_test',
log_uri='s3://xxx/logs',
master_instance_type='m1.small',
slave_instance_type='m1.small',
num_instances=1,
action_on_failure='TERMINATE_JOB_FLOW',
keep_alive=False,
bootstrap_actions=[bootstrap_action],
steps=[step])
Notice that the ``bootstrap_action` argument is different here.

Categories

Resources