need4swede / Portall

Port Management Interface
MIT License
309 stars 5 forks source link

Cannot import since latest version #18

Closed Buco7854 closed 2 months ago

Buco7854 commented 2 months ago

Seems like latest release broke the json import feature.

POST /import HTTP/1.1" 500 -
portall  | ERROR:app:Exception on /import [POST]
portall  | Traceback (most recent call last):
portall  |   File "/app/utils/routes/imports.py", line 184, in import_json
portall  |     data = json.loads(content)
portall  |   File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
portall  |     return _default_decoder.decode(s)
portall  |   File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
portall  |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
portall  |   File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
portall  |     obj, end = self.scan_once(s, idx)
portall  | json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
portall  | 
portall  | During handling of the above exception, another exception occurred:
portall  | 
portall  | Traceback (most recent call last):
portall  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1473, in wsgi_app
portall  |     response = self.full_dispatch_request()
portall  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 882, in full_dispatch_request
portall  |     rv = self.handle_user_exception(e)
portall  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 880, in full_dispatch_request
portall  |     rv = self.dispatch_request()
portall  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 865, in dispatch_request
portall  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
portall  |   File "/app/utils/routes/imports.py", line 44, in import_data
portall  |     imported_data = import_json(file_content)
portall  |   File "/app/utils/routes/imports.py", line 195, in import_json
portall  |     raise ValueError("Invalid JSON format")
portall  | ValueError: Invalid JSON format
portall  | INFO:werkzeug:192.168.1.68 - - [12/Jul/2024 00:57:38] "POST /import HTTP/1.1" 500 -

Data:

[{'ip_address': '192.168.1.68', 'nickname': 'monitor-server-1', 'port_number': 9020, 'description': 'portall', 'order': 0, 'port_protocol': 'TCP'}]
need4swede commented 2 months ago

Is that from an export using Portall?

Property values are single quoted in your data. JSON requires double quotes. All Portall exports use double quotes, but let me know if it somehow produced single quotes.

Here is your data, using double quotes. It should work.

[{"ip_address": "192.168.1.68", "nickname": "monitor-server-1", "port_number": 9020, "description": "portall", "order": 0, "port_protocol": "TCP"}]
Buco7854 commented 2 months ago

Is that from an export using Portall?

Property values are single quoted in your data. JSON requires double quotes. All Portall exports use double quotes, but let me know if it somehow produced single quotes.

Here is your data, using double quotes. It should work.

[{"ip_address": "192.168.1.68", "nickname": "monitor-server-1", "port_number": 9020, "description": "portall", "order": 0, "port_protocol": "TCP"}]

No it wasnt using portal thanks for the pointer sorry.

need4swede commented 2 months ago

No worries! Let me know if you encounter any more issues.

Thank you!