Namespace Secret not available on Raspberry Pi - python

I'm trying to retrieve a cookie on my Raspberry Pi 3B+ with pycookiecheat since pycookiecheat doesn't work on windows. The reason I want to do this is that I need to bypass a login that has multiple steps.
from pycookiecheat import chrome_cookies
import requests
url = 'google.com'
cookies = chrome_cookies(url)
r = requests.get(url, cookies=cookies)
print(r.text)
But there's an error:
Traceback (most recent call last):
File "/home/pi/Desktop/Homeworker.py", line 7, in <module>
cookies = chrome_cookies(url)
File "/home/pi/.local/lib/python3.7/site-packages/pycookiecheat/pycookiecheat.py", line 199, in chrome_cookies
config = get_linux_config(browser)
File "/home/pi/.local/lib/python3.7/site-packages/pycookiecheat/pycookiecheat.py", line 133, in get_linux_config
gi.require_version("Secret", "1")
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Secret not available
>>> %Run Homeworker.py
Traceback (most recent call last):
File "/home/pi/Desktop/Homeworker.py", line 7, in <module>
cookies = chrome_cookies(url)
File "/home/pi/.local/lib/python3.7/site-packages/pycookiecheat/pycookiecheat.py", line 199, in chrome_cookies
config = get_linux_config(browser)
File "/home/pi/.local/lib/python3.7/site-packages/pycookiecheat/pycookiecheat.py", line 133, in get_linux_config
gi.require_version("Secret", "1")
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Secret not available

Related

Can we convert google-cloud-dialogflow api returned types to json?

I having trouble converting dialogflow types such as ListIntentsResponse, EntityType to json. I have researched a lot into this. Converting every entry one by one is a headache thats why I want a workaround.
I have tried using google.protobuf.json_format methods. But it doesnt works. says UNknown field : DESCRIPTOR
from google.protobuf.json_format import *
client = dialogflow.IntentsClient()
request = dialogflow.ListIntentsRequest(
parent=f'projects/{DIALOGFLOW_PROJECT_ID}/agent'
)
response = client.list_intents(request)
# print(response)
print(MessageToJson(response ,descriptor_pool=None))```
**Error==>>>**
Traceback (most recent call last):
File "c:\Users\1150-Bilal\Desktop\chatbot\intents.py", line 12, in <module>
intentlist()
File "c:\Users\1150-Bilal\Desktop\chatbot\intents.py", line 10, in intentlist
print(MessageToJson(response ,descriptor_pool=None))
File "C:\Users\1150-Bilal\Desktop\chatbot\botenv\lib\site-packages\google\protobuf\json_format.py", line 130, in MessageToJson
return printer.ToJsonString(message, indent, sort_keys, ensure_ascii)
File "C:\Users\1150-Bilal\Desktop\chatbot\botenv\lib\site-packages\google\protobuf\json_format.py", line 197, in ToJsonString
js = self._MessageToJsonObject(message)
File "C:\Users\1150-Bilal\Desktop\chatbot\botenv\lib\site-packages\google\protobuf\json_format.py", line 203, in _MessageToJsonObject
message_descriptor = message.DESCRIPTOR
File "C:\Users\1150-Bilal\Desktop\chatbot\botenv\lib\site-packages\google\cloud\dialogflow_v2\services\intents\pagers.py", line 74, in __getattr__
return getattr(self._response, name)
File "C:\Users\1150-Bilal\Desktop\chatbot\botenv\lib\site-packages\proto\message.py", line 747, in __getattr__
raise AttributeError(
AttributeError: Unknown field for ListIntentsResponse: DESCRIPTOR

Unable to parse .nt file with rdflib

My my_data.nt file looks like this:
<bob> <name> "Robert" .
<bob> <knows> <amy> .
I am using this code to parse it:
from rdflib import Graph
g = Graph()
g.parse("my_data.nt", format="nt")
for ele in g:
print(ele)
I am getting this error:
Traceback (most recent call last):
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 140, in parse
self.parseline()
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 189, in parseline
subject = self.subject()
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 216, in subject
subj = self.uriref() or self.nodeid()
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 235, in uriref
uri = self.eat(r_uriref).group(1)
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 210, in eat
raise ParseError("Failed to eat %s at %s" % (pattern.pattern, self.line))
rdflib.plugins.parsers.ntriples.ParseError: Failed to eat <([^:]+:[^\s"<>]+)> at <bob> <name> "Robert" .
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_query.py", line 5, in <module>
g.parse("my_data.nt", format="nt")
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/graph.py", line 1043, in parse
parser.parse(source, self, **args)
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/nt.py", line 26, in parse
parser.parse(f)
File "/Users/x/MyVirtualEnvs/new_python3_env/lib/python3.7/site-packages/rdflib/plugins/parsers/ntriples.py", line 142, in parse
raise ParseError("Invalid line: %r" % self.line)
rdflib.plugins.parsers.ntriples.ParseError: Invalid line: '<bob> <name> "Robert" .'
What am I missing?
When I try contents of my_data.nt on easyrdf it appears to be perfectly fine.

Send sendtextmessage via ts3 api

I have a problem. I have the following code:
import ts3
import time
with ts3.query.TS3Connection("185.201.114.62") as ts3conn:
ts3conn.login(client_login_name="serveradmin", client_login_password="password")
ts3conn.use(sid=1)
ts3conn.send_keepalive()
for client in ts3conn.clientlist():
for cm in ts3conn.clientgetuidfromclid(clid=client["clid"]):
#print(cm["cluid"])
ts3conn.sendtextmessage(targetmode=1, target=cm["cluid"], msg="test")
And if I execute the code I get:
Traceback (most recent call last):
File "C:/Users/kacpe/PycharmProjects/ts3bot/main.py", line 12, in <module>
ts3conn.sendtextmessage(targetmode=1, target=cm["cluid"], msg="test")
File "C:\Users\kacpe\.virtualenvs\ts3bot\lib\site-packages\ts3\commands.py", line 2909, in sendtextmessage
return self._return_proxy("sendtextmessage", cparams, uparams, options)
File "C:\Users\kacpe\.virtualenvs\ts3bot\lib\site-packages\ts3\query.py", line 469, in _return_proxy
self, command, common_parameters, unique_parameters, options)
File "C:\Users\kacpe\.virtualenvs\ts3bot\lib\site-packages\ts3\query.py", line 446, in send
return self._wait_for_resp(timeout=timeout)
File "C:\Users\kacpe\.virtualenvs\ts3bot\lib\site-packages\ts3\query.py", line 383, in _wait_for_resp
raise TS3QueryError(resp)
ts3.query.TS3QueryError: error id 1540: convert error
If I set targetmode to 2 (send message to channel) the code works, normal sending.

How to run playbook api in Ansible with vault

I have a playbook with vault, and I can run it through:
ansible-playbook info.yml --ask-vault-pass
Now, I want to run my playbook api in Ansible. The answer in How to run playbook api in Ansible v2 with vault said that we can set
loader = DataLoader()
loader.set_vault_password('mypass')
in 2.2.0.0 API, and I also set these in my apiļ¼Œbut it doesn't work. The error message is as follows:
Traceback (most recent call last):
File "test2.py", line 63, in <module>
playbook.run()
File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 82, in run
pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader)
File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 54, in load
pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager)
File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 78, in _load_playbook_data
ds = self._loader.load_from_file(os.path.basename(file_name))
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 130, in load_from_file
(b_file_data, show_content) = self._get_file_contents(file_name)
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 206, in _get_file_contents
data = self._vault.decrypt(data, filename=b_file_name)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 561, in decrypt
plaintext, vault_id = self.decrypt_and_get_vault_id(vaulttext, filename=filename)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 617, in decrypt_and_get_vault_id
_matches = match_secrets(self.secrets, vault_id_matchers)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 456, in match_secrets
matches = [(vault_id, secret) for vault_id, secret in secrets if vault_id in target_vault_ids]
ValueError: need more than 1 value to unpack
Then I change the
loader.set_vault_password('mypass')
to
loader.set_vault_secrets([('default','mypass')])
But it doesn't work either. The error message is:
Traceback (most recent call last):
File "test2.py", line 63, in <module>
playbook.run()
File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 82, in
pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._l
File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 54, in load
pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager)
File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 78, in _load_pla
ds = self._loader.load_from_file(os.path.basename(file_name))
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 130, in load_fr
(b_file_data, show_content) = self._get_file_contents(file_name)
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 206, in _get_fi
data = self._vault.decrypt(data, filename=b_file_name)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 561, in dec
plaintext, vault_id = self.decrypt_and_get_vault_id(vaulttext, filename=filename)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 638, in dec
b_plaintext = this_cipher.decrypt(b_vaulttext, vault_secret)
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 1344, in de
b_password = secret.bytes
AttributeError: 'str' object has no attribute 'bytes'
I try to change the line
b_password = secret.bytes
in file /usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py to
b_password = secret
then the api works normally. But I think it's not a good way to basically solve my problem.
Use VaultSecret class instead of string password:
from ansible.module_utils._text import to_bytes
from ansible.parsing.vault import VaultSecret
loader.set_vault_secrets([('default',VaultSecret(_bytes=to_bytes('123456')))])

Open a new instance of AutoCAD via Python

Does anyone have any experience using Python with AutoCAD? I'm just trying, as a test to see if I can open a new instance of AutoCAD via Python and though that PyAutocad worked well (feel free to offer other suggestions, if you have any).
Anyway based on the doc (https://pypi.python.org/pypi/pyautocad/#downloads) - it says these lines of code should do it, but nothing's happened as of yet.
from pyautocad import Autocad, APoint
acad = Autocad()
acad.prompt("Hello, Autocad from Python\n")
Just these lines of code should generate info on the commandline but instead results in about 50 lines worth of traceback (which I can post as well if anyone's interested) - any ideas?
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
acad.prompt("Hello, Autocad")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 54, in app
self._app = comtypes.client.GetActiveObject('AutoCAD.Application')
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 180, in GetActiveObject
obj = comtypes.GetActiveObject(clsid, interface=interface)
File "C:\Python27\lib\site-packages\comtypes\__init__.py", line 1165, in GetActiveObject
oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
File "_ctypes/callproc.c", line 941, in GetResult
WindowsError: [Error -2147221021] Operation unavailable
After adding the VBA Module, the traceback now reads:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
acad.prompt("Hello")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 54, in app
self._app = comtypes.client.GetActiveObject('AutoCAD.Application')
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 183, in GetActiveObject
return _manage(obj, clsid, interface=interface)
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: 'module' object has no attribute 'IAcadApplication'
Now after deleting comtypes' "gen" folder per #reclosedev, Autocad now opens but the string of text still will not appear on the command line - the traceback reads:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
acad.prompt("Hello")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 59, in app
self._app.Visible = self._visible
File "C:\Python27\lib\site-packages\comtypes\client\dynamic.py", line 116, in __setattr__
dispid = self._comobj.GetIDsOfNames(name)[0]
File "C:\Python27\lib\site-packages\comtypes\automation.py", line 643, in GetIDsOfNames
self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids)
COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
Have you considered IronPython?
http://through-the-interface.typepad.com/through_the_interface/2009/03/using-ironpython-with-autocad.html
Here's a quick example of how it could be leveraged:
import clr
import System
from System import Type, Activator
acApp = Activator.CreateInstance(Type.GetTypeFromProgID("AutoCAD.Application"))
acApp.Visible = 1
acApp.ActiveDocument.SendCommand("(Princ \"Hello World from Python!\")(Princ)\n")
Obviously the ProgId will correspond to whichever version of AutoCAD was opened last.

Categories

Resources