Categories
Mastering Development

connexion jsonschema.exceptions- Unknown type ‘str’ for validator with schema:

I used flask and connexion for my api, I got python server stub from swagger editor and it was generated based on api spec. However, one of my endpoint make request with json data, it should be validated by json schema validator. I used jsonschema python library for that. But, now when I test endpoint […]

Categories
Mastering Development System & Network

Server crash (Error 500) repeatedly (running nginx + gunicorn on EC2 instance)

Okay, so I’m really confused about what’s happening here. I’ve had my server up and running for about a month and everything was fine. The server was getting very little traffic (about 50-100 requests per day) so I figured that should be the least of my problems. Then, one day I noticed the server is […]

Categories
User Help Web Apps

TypeError: cannot pickle ‘_thread._local’ objectI am trying to run following code

I have made a register route and function which will add new users to the database. The code is working fine, messages are flashed according to the condition, but the only problem is that when I try to register a new user, it says; Traceback (most recent call last): File “C:\Users\Habiba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask\app.py”, line 2463, in __call__ […]

Categories
Mastering Development

***SOLVED*** Python Multi-Threaded Logging

I’m trying to write a simple port-checking program that tests VMware Horizon network ports. The port-checking itself is working just fine, but my “multi-threaded” logging is falling short between lines 71 and 91. I know for a fact I’m doing this wrong because I piecemeal-ed the logging portion together from multiple posts online. I have […]

Categories
Mastering Development

Python: SqlAlchemy map existing view to ORM Object

I currently try to map an existing view within my postgreSQL DB to an SqlAlchemy ORM object in python. My view has the following name path_number_view and joins some tables together. It is wokring fine. But I am not able to map the view to an ORM object, when starting the application I get an […]

Categories
Mastering Development

Unabe to return my value after the api call – getting TypeError: ‘dict’ object is not callable

I am trying to fetch values from an api and return it using api call. When i try to call the api function , I am facing TypeError: ‘dict’ object is not callable. My Code is below from flask import Flask, request, jsonify import json import requests import datetime import sys app = Flask(__name__) port […]

Categories
Mastering Development

flask_restful – TypeError: Object of type Record is not JSON serializable

I try to provide a custom object inside a rest api, created with flask_restful. Object: Record import json class Record(): #CLASS RECORD def __init__(self, DateTime, DateTimeText, Status, Icon, Temp): #INITIALIZE self.DateTime = DateTime self.DateTimeText = DateTimeText self.Status = Status self.Icon = Icon self.Temp = Temp def __repr__(self): return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4) Result: […]

Categories
Development

ValueError: cannot infer type for

I’m trying to upload a dataframe to sqlite database which has no problem unless I add the ‘quarters’ column. df[‘quarters’] = pd.PeriodIndex(pd.df(empres_df.date), freq=’Q’) df.to_sql(“table_name”, con, if_exists=”append”) Because when I do, it gives me this error: Traceback (most recent call last): File “/opt/anaconda3/lib/python3.7/site-packages/flask/app.py”, line 2446, in wsgi_app response = self.full_dispatch_request() File “/opt/anaconda3/lib/python3.7/site-packages/flask/app.py”, line 1951, in full_dispatch_request […]

Categories
Development

How to define a ContextManager Protocol

I am trying to use type hinting to specify the API to follow when implementing a connector class (to a broker, in this case). I want to specify that such class(es) should be context manager(s) How do I do that? I know how to do it with ABC’s, but I would like to learn how […]

Categories
AJAX API Development

Connecting via Paramiko SSH using AJAX API call

I’m setting up a rest like API which will interrogate Linux services (enable, disable, status, start, stop), however when sending an AJAX api call, it won’t connect, but if I send a curl request via the terminal on the same machine the web server is hosted on, it will work. The front end sits on […]