Unable to parse .nt file with rdflib - python

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.

Related

Stuck with connecting to mongodb

I was about to start using mongodb as my database project. I'm always stuck when want to pushing some data to it. I use mongodb atlas. This code below always resulting errors. I've following and learning about mongodb from online (like youtube, w3, etc)
import pymongo
from pymongo import MongoClient
url = "mongodb+srv://<username>:<password>#cluster0.oecqh.mongodb.net/test?retryWrites=true&w=majority"
cluster = MongoClient(url)
db = cluster["discord"]
collection = db["discord"]
push = {"name": "test", "value": "test"}
try:
collection.insert_one(push)
except Exception as e:
print(e)
The errors
Exception ignored in: <function Client.__del__ at 0x00000213C5D84940>
Traceback (most recent call last):
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\httpx\_client.py", line 1139, in __del__
self.close()
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\httpx\_client.py", line 1111, in close
self._transport.close()
AttributeError: 'Client' object has no attribute '_transport'
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\win32util.py", line 48, in run
self.info.domain = _config_domain(interface.DNSDomain)
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\win32util.py", line 26, in _config_domain
if domain.startswith('.'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Traceback (most recent call last):
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\srv_resolver.py", line 89, in _resolve_uri
results = _resolve(
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\srv_resolver.py", line 43, in _resolve
return resolver.resolve(*args, **kwargs)
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\resolver.py", line 1193, in resolve
return get_default_resolver().resolve(qname, rdtype, rdclass, tcp, source,
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\resolver.py", line 1063, in resolve
(nameserver, port, tcp, backoff) = resolution.next_nameserver()
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\resolver.py", line 646, in next_nameserver
raise NoNameservers(request=self.request, errors=self.errors)
dns.resolver.NoNameservers: All nameservers failed to answer the query _mongodb._tcp.cluster0.oecqh.mongodb.net. IN SRV:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\chris\OneDrive\Documents\Programming\Python\tempCodeRunnerFile.py", line 5, in <module>
cluster = MongoClient(url)
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\mongo_client.py", line 704, in __init__
res = uri_parser.parse_uri(
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\uri_parser.py", line 542, in parse_uri
nodes = dns_resolver.get_hosts()
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\srv_resolver.py", line 121, in get_hosts
_, nodes = self._get_srv_response_and_hosts(True)
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\srv_resolver.py", line 101, in _get_srv_response_and_hosts
results = self._resolve_uri(encapsulate_errors)
File "C:\Users\chris\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\srv_resolver.py", line 97, in _resolve_uri
raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: All nameservers failed to answer the query _mongodb._tcp.cluster0.oecqh.mongodb.net. IN SRV:

python > Selenium > Traceback

I tried a lot to fix Traceback Error
The same code is working in Pycharm , But when I put it in replit.com , is shows this Error
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/xauth.py", line 43, in __init__
raw = open(filename, 'rb').read()
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.Xauthority'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 9, in <module>
import pyautogui
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/protocol/display.py", line 60, in __init__
auth_name, auth_data = connect.get_auth(self.socket,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/support/connect.py", line 91, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/support/unix_connect.py", line 103, in new_get_auth
au = xauth.Xauthority()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/Xlib/xauth.py", line 45, in __init__
raise error.XauthError('~/.Xauthority: %s' % err)
Xlib.error.XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/runner/.Xauthority'
please help me
Try this:
sudo apt-get install xauth
If it doesn't work there are other answers to the problem in here

Namespace Secret not available on Raspberry Pi

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

EOF error when I try to use 'expect' function from'Pexpect'

I'm trying to automate the process of switch between networks in "Cisco AnyConnect", but my code always is terminated with an 'EOF error'.
I've tried a search in API doc for some help and used different expressions like: "Network", "Network:" or "Network.*".
from pexpect import popen_spawn
import pexpect
vpnui = pexpect.popen_spawn.PopenSpawn(r'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe', maxread=2000)
vpnui.expect('Network:')
vpnui.sendline('SomeNetwork')
The error:
Traceback (most recent call last): File
"C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py",
line 111, in expect_loop
incoming = spawn.read_nonblocking(spawn.maxread, timeout) File "C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\popen_spawn.py",
line 75, in read_nonblocking
raise EOF('End Of File (EOF).') pexpect.exceptions.EOF: End Of File (EOF).
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\myUser\eclipse-workspace\teste\switchGuestWifi.py", line 15,
in
vpnui.expect('Network:') File "C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\spawnbase.py",
line 341, in expect
timeout, searchwindowsize, async_) File "C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\spawnbase.py",
line 369, in expect_list
return exp.expect_loop(timeout) File "C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py",
line 117, in expect_loop
return self.eof(e) File "C:\Users\myUser\AppData\Local\Programs\Python\Python36\lib\site-packages\pexpect\expect.py",
line 63, in eof
raise EOF(msg) pexpect.exceptions.EOF: End Of File (EOF).
searcher: searcher_re:
0: re.compile(b'Network:')

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