python 2.7 and opencv code gives cvtcolor error

Issue faceCascade = cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’) video_capture = cv2.VideoCapture(0) while True: ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale( frame, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.cv.CV_HAAR_SCALE_IMAGE ) # Draw a rectangle around the faces for (x, y, w, h) in

Continue reading

c++ using-keyword in python

Issue In c++ you generally can do this: using LCN = longNamespace::sub::subsub::LongClassName so you don’t have to write a long classname everytime. Is there a similar keyword or workaround in python for static classmethods. class MyPythonClassWithLongName: @staticmethod def foo(): pass

Continue reading

how to display exact line number (where the error has occured) in logging library

Issue In the following code, the error is at line 7. However, log displays error at line 10, where logging is mentioned. import logging import urllib2 logging.basicConfig(filename=’example.log’,level=logging.DEBUG,format=’%(levelname) -10s %(asctime)s %(module)s:%(lineno)s %(funcName)s %(message)s’) def main(): try: urls = “http://www.simplyhired.com/a/job-detaw/jobkey-67b4efe169eee7b2cf2ed47d49b1845070ea37/rid-racliggzfyjgqwfzrlvnqyjtcserhrri/cjp-3/pub_id-1002” site =

Continue reading

How can I send an email using python logging's SMTPHandler and SSL

Issue I’m developing a flask app in which I’d like to send error level logging to an email address. I tried setting up the typical error handler: mail_handler = SMTPHandler(mailhost=(app.config[‘MAIL_SERVER’], app.config[‘MAIL_PORT’]), fromaddr=app.config[‘MAIL_FROM_EMAIL’], toaddrs=[‘me@my_address.com’], subject=’The server died. That sucks… :(‘, credentials=(app.config[‘MAIL_USERNAME’],

Continue reading

Logging in Python console and in log file

Issue I’m using the logging library and would like to log on to the console and store those logs in a file. logger = logging.getLogger(module) handler = logging.StreamHandler() formatter = logging.Formatter( ‘%(asctime)s [%(name)s] %(levelname)-8s %(message)s’) handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) filehandler=logging.FileHandler(‘logfile.log’) logger.addHandler(filehandler)

Continue reading

Images are not being stored?? – Django

Issue These are my following settings: MEDIA_ROOT = ‘/home/webapps/test_project/media/’ MEDIA_URL = ‘http://192.168.0.2:8090/site_media/’ ADMIN_MEDIA_PREFIX = ‘/media/’ These are my model fields: large = models.ImageField(blank=True, null=True, upload_to=”images”) thumb = models.ImageField(blank=True, null=True, upload_to=”images”) What happens is… when I save a model with the

Continue reading

File upload form in Django

Issue I’m trying to create a simple upload form for my project in Django 1.5 an Python 2.7. This is my File class: class File(models.Model): middleschool = ‘MS’ highschool = ‘HS’ university = ‘U’ blank = ‘-‘ school_choices = ((middleschool,

Continue reading

Django image upload succeeds with url written to DB but no image shows upload target folder

Issue I have form in Django class BusinessForm(forms.Form): name = forms.CharField( required = True, max_length=MAX_NAME_LENGTH, widget=forms.TextInput(attrs={‘placeholder’: ‘e.g Boston Market’})) image = forms.ImageField() which belongs to this model class Business(models.Model): “”” Describes Bussines data type “”” name = models.CharField(max_length=BUS_NAME_LENGTH) img =

Continue reading

Cannot upload image in django using filefield

Issue I am not able to upload image. here is my models.py class Post(models.Model): author = models.ForeignKey(‘auth.User’) title = models.CharField(max_length=200) text = models.TextField() image = models.FileField(upload_to = ‘post/static/images/’ , null= True, blank= True) created_date = models.DateTimeField(default=timezone.now) published_date = models.DateTimeField(blank=True, null=True)

Continue reading

How do I save the foreign key?

Issue I want to upload multiple images. class IssuePanel(models.Model): issue = models.ForeignKey(ComicIssue, on_delete=models.CASCADE) panel = models.FileField(upload_to=’comic_issues_files/panels/’) date_uploaded = models.DateTimeField(auto_now_add=True) After following the examples on django-multiupload’s repository on github, I have this on forms.py class PanelsForm(forms.ModelForm): class Meta: model = ComicIssue

Continue reading

Django cant upload image

Issue I am trying to add avatar to my model, but uploading dosent work. settings.py MEDIA_ROOT = os.path.join(PROJECT_ROOT, ‘media’) MEDIA_URL = ‘/media/’ models.py class Casting(models.Model): … casting_picture = ImageField(upload_to=’/media/photos’) template casting.html there a lot of fields, so in short: <form

Continue reading

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

Issue How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view([‘POST’, ‘GET’]) def create_post(request): if request.method == ‘POST’: altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data[‘files’] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return

Continue reading

Django ImageField – render only the <input> element

Issue I have a Django form which has an ImageField in it, and I render the field like this in my template: {{ form.my_image_field }} The resulting HTML looks like this: Currently: <a href=”https://….s3.amazonaws.com/….jpg”>….jpg</a> <input name=”my_image_field-clear” id=”my_image_field-clear_id” type=”checkbox”> <label for=”my_image_field-clear_id”>Clear</label><br>

Continue reading

Django long polling request timed-out

Issue Django 3.2 DRF run using ./mange runserver when deploying planing to use ‘nginx, uwsgi’ here is my backend code class ChatHandler(APIView): queryset = Chat.objects.all() serialzier_class = MessageSerializer def get_queryset(self): return self.queryset.filter(name=self.kwargs[‘room’]).get() def get(self, request, room): optionail_last_message_time = request.data.get(‘at’) new_messages

Continue reading

I cant create a page with an empty path in Django

Issue centralsite/views def centralsite(request): return render(request, ‘centralsite/text.html’, {}) centralsite/urls from django.urls import path from . import views urlpatterns = [ path(”, views.centralsite, name=’centralsite’), ] urls.py from django.contrib import admin from django.urls import include, path urlpatterns = [path(‘ ‘, include(‘centralsite.urls’)), path(‘polls/’,

Continue reading

NoReverseMatch at /product/pussyes/ Reverse for 'basket_adding' not found. 'basket_adding' is not a valid view function or pattern name

Issue NoReverseMatch at /product/pussyes/ Reverse for ‘basket_adding’ not found. ‘basket_adding’ is not a valid view function or pattern name. Request Method: GET Request URL: http://127.0.0.1:8000/product/pussyes/ Django Version: 1.11 Exception Type: NoReverseMatch Exception Value: Reverse for ‘basket_adding’ not found. ‘basket_adding’ is

Continue reading

Flask and React routing

Issue I’m building the Flask app with React, I ended up having a problem with routing. The backend is responsible to be an API, hence some routes look like: @app.route(‘/api/v1/do-something/’, methods=[“GET”]) def do_something(): return something() and the main route which

Continue reading

Convert columns in (.csv) file to (.json) column array in Python

Issue I am trying to convert a (.csv) file to a .json file which is stored in the form of a column array. The input (.csv) file is: This is my desired result: { "wavelength":[0.033962528,0.035974933,0.03801894,0.039994474,0.041975898,0.043954162], "n":[0.842171,0.83072,0.819753,0.809997,0.802291,0.797737], "k":[0.090738197,0.10934279,0.13025372,0.15338756,0.17980019,0.20882868], "alpha":[33573761.42,38194428.97,43052660.58,48194781.27,53826980.05,59703529.05], "absorption_length":[2.98e-8,2.62e-8,2.32e-8,2.07e-8,1.86e-8,1.67e-8] }

Continue reading

Extracting a column out

Issue I have a list of array of the form. params = [[array([7.30946927, 2.40445369])], [array([7.30886254, 2.40241312])], [array([7.21275251, 2.09358208])], [array([7.61757898, 0.15745312])], [array([7.76890152, 2.70100186])], [array([7.82943027, 2.39066977])], [array([7.20117715, 2.05259557])], [array([7.21455828, 2.09081677])], [array([7.46129784, 1.9455824 ])]] I want to extract out the first element (7.3,

Continue reading