pyrad
pyrad copied to clipboard
FileNotFoundError: [Errno 2] No such file or directory
Hello,
I ask for forgiveness ahead of time. I'm a python newbie.
I installed pyrad via: pip install pyrad
I'm getting this when I run the example (with server/server info updated):
(env) $ python fas/radius.py Traceback (most recent call last):
File "fas/radius.py", line 6, in <module>
srv = Client(server="X.X.X.X", secret=b"XXXXXXXX", dict=Dictionary("dictionary"))
File "/fas/env/lib/python3.7/site-packages/pyrad/dictionary.py", line 164, in __init__
self.ReadDictionary(dict)
File "/fas/env/lib/python3.7/site-packages/pyrad/dictionary.py", line 357, in ReadDictionary
fil = dictfile.DictFile(file)
File "/fas/env/lib/python3.7/site-packages/pyrad/dictfile.py", line 54, in __init__
self.__ReadNode(fil)
File "/fas/env/lib/python3.7/site-packages/pyrad/dictfile.py", line 65, in __ReadNode
fd = open(fname, "rt")
FileNotFoundError: [Errno 2] No such file or directory: '/fas/dictionary'
This is the python file:
from __future__ import print_function
from pyrad.client import Client
from pyrad.dictionary import Dictionary
import pyrad.packet
srv = Client(server="x.x.x.x", secret=b"XXXXX", dict=Dictionary("dictionary"))
# create request
req = srv.CreateAuthPacket(code=pyrad.packet.AccessRequest, User_Name="xxxxx", NAS_Identifier="xxxxx")
req["User-Password"] = req.PwCrypt("password")
# send request
reply = srv.SendPacket(req)
if reply.code == pyrad.packet.AccessAccept:
print("access accepted")
else:
print("access denied")
print("Attributes returned by server:")
for i in reply.keys():
print("%s: %s" % (i, reply[i]))
Do you have a RADIUS dictionary in your current folder? If not you either need one or adjust srv = Client(server="x.x.x.x", secret=b"XXXXX", dict=Dictionary("dictionary")) to srv = Client(server="x.x.x.x", secret=b"XXXXX", dict=Dictionary("/location/to/my/dictionary")). Usually the dictionary is either self contained or $INCLUDEs other dictionary files.
You can find a small dictionary in https://github.com/pyradius/pyrad/tree/master/example/dictionary . This dictionary contain "only" RADIUS Attributes from RFC 2865 and/or RFC 2866.
For more RFC Attributes or Vendor specific Attributes check out the dictionaries from FreeRADIUS: https://github.com/redBorder/freeradius/tree/master/share .
I had to update the auth example like this:
import os
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
dictionary_file = os.path.join(THIS_FOLDER,'dictionary')
print(dictionary_file)
srv = Client(server="x.x.x.x", secret=b"xxxx", dict=Dictionary(dictionary_file))