M
M
Maxim2020-08-19 11:37:33
Python
Maxim, 2020-08-19 11:37:33

How to call a class method inside a class?

When I try to call a method inside a class from another method, I get an error:

'GetRequestsUTM' object has no attribute '_UTMRequests_connect'


import requests, xmltodict
from rest_framework import generics
from UTMWatch.models import *

class UTMRequests():

    def __connect(workplase):
        r = requests.get('http://'+workplase.VirtualIPAddress+':'+workplase.port+'/opt/out')
        return xmltodict.parse(r.text)

    def syns(self, workplase):
        o = self.__connect(workplase=workplase)
        if 'url' in o['A']:
            for i in range(len(o['A']['url'])):
                if isinstance(o['A']['url'],list) != True:
                    if '#text' in o['A']['url'] and '@replyId' in o['A']['url']:
                        #Если не накладная
                        if not RequestUtmList.objects.filter(link = o['A']['url']['#text']).exists():
                            type = re.split(r'/', o['A']['url']['#text'])
                            RequestUtmList.objects.create(replyId = o['A']['url']['@replyId'], type = type[-2], link = o['A']['url']['#text'], workplase = workplase)
                        if workplase.RemoveRequests:
                            requests.delete(o['A']['url']['#text'])
                    else:
                        #Накладные
                        if not RequestUtmList.objects.filter(link = o['A']['url']).exists():
                            type = re.split(r'/', o['A']['url'])
                            RequestUtmList.objects.create(replyId = '', type = type[-2], link = o['A']['url'], workplase = workplase)
                        if workplase.RemoveRequests:
                            requests.delete(o['A']['url'])
                else:
                    if '#text' in o['A']['url'][i] and '@replyId' in o['A']['url'][i]:
                        #Если не накладная
                        if not RequestUtmList.objects.filter(link = o['A']['url'][i]['#text']).exists():
                            type = re.split(r'/', o['A']['url'][i]['#text'])
                            RequestUtmList.objects.create(replyId = o['A']['url'][i]['@replyId'], type = type[-2], link = o['A']['url'][i]['#text'], workplase = workplase)
                        if workplase.RemoveRequests:
                            requests.delete(o['A']['url'][i]['#text'])
                    else:
                        #Накладные
                        if not RequestUtmList.objects.filter(link = o['A']['url'][i]).exists():
                            type = re.split(r'/', o['A']['url'][i])
                            RequestUtmList.objects.create(replyId = '', type = type[-2], link = o['A']['url'][i], workplase = workplase)
                        if workplase.RemoveRequests:
                            requests.delete(o['A']['url'][i])
        return True


###########

class GetRequestsUTM(APIView):
    def get_object(self, pk):
        try:
            return WorkPlases.objects.get(pk=pk)
        except WorkPlases.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        workplase = self.get_object(pk)
        try:
            return Response(UTMRequests.syns(self, workplase=workplase))
        except ConnectionError:
            return Response({"detail" : "Remote UTM Connection Error"}, status=status.HTTP_502_BAD_GATEWAY)

what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pikeev, 2020-08-19
@Baryon

what am I doing wrong?

Don't show the full code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question