Twython: How to update profile banner? - python-3.x

What am I doing wrong?
twitter = twython.Twython(api_key, api_secret, access_token, token_secret)
banner_file = open('banner.jpg', 'rb')
twitter.update_profile_banner_image(banner=banner_file)
Calling this returns:
Traceback (most recent call last): File
"/usr/local/lib/python3.5/dist-packages/twython/api.py", line 202, in
_request
content = response.json() File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 812,
in json
return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "tuit.py", line 45, in
twitter.update_profile_banner_image(banner=banner) File "/usr/local/lib/python3.5/dist-packages/twython/endpoints.py", line
493, in update_profile_banner_image
return self.post('account/update_profile_banner', params=params) File "/usr/local/lib/python3.5/dist-packages/twython/api.py", line
270, in post
return self.request(endpoint, 'POST', params=params, version=version) File
"/usr/local/lib/python3.5/dist-packages/twython/api.py", line 260, in
request
api_call=url) File "/usr/local/lib/python3.5/dist-packages/twython/api.py", line 205, in
_request
Unable to decode.') twython.exceptions.TwythonError: Response was not valid JSON. Unable to decode.

Related

Azure-quantum: problems with jobs submission

I use pyquil for azure quantum, and submit jobs with run_batch method of AzureQuantumComputer class. For batches with up to 10 circuits there are no problems, but larger batches result in an error below.
Traceback (most recent call last):
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1436, in _deserialize
found_value = key_extractor(attr, attr_desc, data)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1180, in rest_key_extractor
return working_data.get(key)
AttributeError: 'str' object has no attribute 'get'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1509, in failsafe_deserialize
return self(target_obj, data, content_type=content_type)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1376, in __call__
return self._deserialize(target_obj, data)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1454, in _deserialize
raise_with_traceback(DeserializationError, msg, err)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\exceptions.py", line
51, in raise_with_traceback
raise error.with_traceback(exc_traceback)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1436, in _deserialize
found_value = key_extractor(attr, attr_desc, data)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\msrest\serialization.py",
line 1180, in rest_key_extractor
return working_data.get(key)
azure.core.exceptions.DeserializationError: ("Unable to deserialize to object: type,
AttributeError: 'str' object has no attribute 'get'", AttributeError("'str' object has no
attribute 'get'"))
Traceback (most recent call last):
File "C:\Users\Enter\PycharmProjects\QREM_pipline_development\pyquil_experiments.py", line
209, in <module>
unprocessed_results_now = pyquil_utilities.run_batches_parametric(backend_name=backend_name,
File
"C:\Users\Enter\PycharmProjects\QREM_SECRET_DEVELOPMENT_LOC\backends_support\pyquil\pyquil_utiliti
es.py", line 415, in run_batches_parametric
results = backend_instance.run_batch(executable,
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\pyquil_for_azure_quantum_init_.py", line 141, in run_batch
return qam.run_batch(executable, memory_map)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\pyquil_for_azure_quantum_init_.py", line 336, in run_batch
job = self._target.submit(
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\quantum\target\rigetti\target.py", line 183, in submit
return super().submit(input_data, name, input_params, **kwargs)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\quantum\target\target.py", line 141, in submit
return Job.from_input_data(
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\quantum\job\base_job.py",
line 117, in from_input_data
return cls.from_storage_uri(
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\quantum\job\base_job.py",
line 207, in from_storage_uri
job.submit()
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\azure\quantum\job\job.py",
line 45, in submit
job = self.workspace.submit_job(self)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-packages\azure\quantum\workspace.py",
line 265, in submit_job
details = client.create(
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\core\tracing\decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Users\Enter\anaconda3\envs\qiskit_env\lib\site-
packages\azure\quantum_client\operations_jobs_operations.py", line 387, in create
raise HttpResponseError(response=response, model=error)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Forbidden'
Content:
403 Forbidden
403 Forbidden
Microsoft-Azure-Application-Gateway/v2
I tried to run different circuits, it seems to only depend on the number of circuits in a batch, not the structure of a circuit. Programs are compiled to native quil locally.

using selenium I get some errors: TypeError: expected str, bytes or os.PathLike object, not NoneType

When I run a test case
python3.9 manage.py test
in django webapp I get some errors.
System check identified no issues (0 silenced).
test_login (pygiustizia.tests.test_views_topics.ViewsTopicsTestCase) ... nel costruttore model Users
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
File "/usr/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1662, in __call__
return super().__call__(environ, start_response)
Traceback (most recent call last):
File "/usr/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1662, in __call__
return super().__call__(environ, start_response)
File "/home/nicola/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
response = self.get_response(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1662, in __call__
return super().__call__(environ, start_response)
File "/home/nicola/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
response = self.get_response(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1645, in get_response
return self.serve(request)
File "/usr/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/nicola/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
response = self.get_response(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1645, in get_response
return self.serve(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1657, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1657, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1645, in get_response
return self.serve(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1657, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/home/nicola/.local/lib/python3.9/site-packages/django/views/static.py", line 35, in serve
fullpath = Path(safe_join(document_root, path))
File "/home/nicola/.local/lib/python3.9/site-packages/django/utils/_os.py", line 17, in safe_join
final_path = abspath(join(base, *paths))
File "/home/nicola/.local/lib/python3.9/site-packages/django/views/static.py", line 35, in serve
fullpath = Path(safe_join(document_root, path))
File "/home/nicola/.local/lib/python3.9/site-packages/django/views/static.py", line 35, in serve
fullpath = Path(safe_join(document_root, path))
File "/home/nicola/.local/lib/python3.9/site-packages/django/utils/_os.py", line 17, in safe_join
final_path = abspath(join(base, *paths))
File "/usr/lib/python3.9/posixpath.py", line 76, in join
a = os.fspath(a)
File "/home/nicola/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1662, in __call__
return super().__call__(environ, start_response)
File "/usr/lib/python3.9/posixpath.py", line 76, in join
a = os.fspath(a)
File "/home/nicola/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
response = self.get_response(request)
File "/home/nicola/.local/lib/python3.9/site-packages/django/utils/_os.py", line 17, in safe_join
final_path = abspath(join(base, *paths))
File "/usr/lib/python3.9/posixpath.py", line 76, in join
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
In this stackoverflow post stackoverflow answer they suggest to set STATIC_ROOT.
I don't know how set this property in settings.py.
The path where I have static files (css,js,images) is
/var/www/html/elastic_queries/python/djangosite/giustiziasite/pygiustizia/static/pygiustizia
What can I do, put path directly in STATIC_ROOT variable?

API Key Authentication Python example raises TypeError

API Key Authentication Python example in the site raises a TypeError:
Traceback (most recent call last):
File "test-coin.py", line 39, in <module>
r = requests.get(api_url + 'user', auth=auth)
File "/usr/lib/python3/dist-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 506, in request
prep = self.prepare_request(req)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 439, in prepare_request
p.prepare(
File "/usr/lib/python3/dist-packages/requests/models.py", line 309, in prepare
self.prepare_auth(auth, url)
File "/usr/lib/python3/dist-packages/requests/models.py", line 540, in prepare_auth
r = auth(self)
File "test-coin.py", line 25, in __call__
signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()
File "/usr/lib/python3.8/hmac.py", line 146, in new
return HMAC(key, msg, digestmod)
File "/usr/lib/python3.8/hmac.py", line 46, in __init__
raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
TypeError: key: expected bytes or bytearray, but got 'str'
The problem is in this part of the code:
def __call__(self, request):
...
signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()
We need to encode self.secret_key and message. Replace the line:
signature = hmac.new(self.secret_key.encode(), message.encode(), hashlib.sha256).hexdigest()
Fixed the issue. I wonder if anyone else stumbled with that error?

Suds-jurko http error

I use python3 and sud-jurko
This my code:
from suds.client import Client
from suds.transport.http import HttpAuthenticated
wsdl_url = 'http://192.168.1.5/Base/ws/ws1.1cws'
t = HttpAuthenticated(username='login', password='pass')
client = Client(url=wsdl_url, transport=t)
print (client)
When run i get error:
(testik) C:\Users\Admin\testik>python test.py
Traceback (most recent call last):
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 67
, in open
return self.u2open(u2request)
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 13
2, in u2open
return url.open(u2request, timeout=tm)
File "C:\Python34\lib\urllib\request.py", line 469, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 579, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 507, in error
return self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 441, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 587, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Authorization Required
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 16, in <module>
client = Client(url=wsdl_url, transport=t)
File "C:\Users\Admin\testik\lib\site-packages\suds\client.py", line 115, in __
init__
self.wsdl = reader.open(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 150, in op
en
d = self.fn(url, self.options)
File "C:\Users\Admin\testik\lib\site-packages\suds\wsdl.py", line 136, in __in
it__
d = reader.open(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 74, in ope
n
d = self.download(url)
File "C:\Users\Admin\testik\lib\site-packages\suds\reader.py", line 92, in dow
nload
fp = self.options.transport.open(Request(url))
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 23
5, in open
return HttpTransport.open(self, request)
File "C:\Users\Admin\testik\lib\site-packages\suds\transport\http.py", line 69
, in open
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 401: Authorization Required
(testik) C:\Users\Admin\testik>
What i am doing wrong. Please help me.
.-----------------------
. ------------------
.------------------
.---------------------
.------------------

how to authenticate in jira with python

from jira.client import JIRA
jira_options={'server': 'https://abcjira.atlassian.net/login?dest- url=%2Fsecure%2FMyJiraHome.jspa'}
jira=JIRA(options=jira_options,basic_auth=('user','password'))
I want to do basic authentication in jira with python. Wrote above code but it gives me traceback. Could anyone please tell me what is the problem here.
Traceback (most recent call last):
File "lab.py", line 5, in <module>
jira=JIRA(options=jira_options,basic_auth=('user','password'))
File "C:\Python34\lib\site-packages\jira\client.py", line 261, in __init__
si = self.server_info()
File "C:\Python34\lib\site-packages\jira\client.py", line 1619, in server_info
return self._get_json('serverInfo')
File "C:\Python34\lib\site-packages\jira\client.py", line 2040, in _get_json
raise e
File "C:\Python34\lib\site-packages\jira\client.py", line 2037, in _get_json
r_json = json_loads(r)
File "C:\Python34\lib\site-packages\jira\utils.py", line 81, in json_loads
return json.loads(r.text)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 4 column 1 (char 3)

Resources