Задать вопрос
maxpoitn2point
@maxpoitn2point
Как всегда, в своем репертуаре

Как обратиться к методу класса внутри класса?

При попытке вызвать метод внутри класса из другого метода получаю ошибку:
'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)

что я делаю не так?
  • Вопрос задан
  • 143 просмотра
Подписаться 1 Простой 8 комментариев
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы