PokemonGo-Bot icon indicating copy to clipboard operation
PokemonGo-Bot copied to clipboard

AttributeError: 'NoneType' object has no attribute 'get'

Open nanogirl21 opened this issue 10 years ago • 6 comments

Getting the below error on each dev pull since the new API fix. I have changed my config.json multiple times based on chat/slack support. Still no luck. My bot stops every few minutes because of this. A fix or suggestion on why this is happening would help so much. Thank you.

ERROR

Traceback (most recent call last):
  File "pokecli.py", line 530, in <module>
    main()
  File "pokecli.py", line 96, in main
    bot.tick()
  File "/Users/Nano/Downloads/PokemonGo-Bot-Dev/pokemongo_bot/__init__.py", line 472, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "/Users/Nano/Downloads/PokemonGo-Bot-Dev/pokemongo_bot/cell_workers/handle_soft_ban.py", line 32, in work
    MoveToFort(self.bot, config=None).work()
  File "/Users/Nano/Downloads/PokemonGo-Bot-Dev/pokemongo_bot/base_task.py", line 12, in __init__
    self.initialize()
  File "/Users/Nano/Downloads/PokemonGo-Bot-Dev/pokemongo_bot/cell_workers/move_to_fort.py", line 16, in initialize
    self.lure_attraction = self.config.get("lure_attraction", True)
AttributeError: 'NoneType' object has no attribute 'get'

Runtime was 2 minutes and 21 seconds

My Move To Fort PY

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pokemongo_bot.constants import Constants
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_task import BaseTask
from utils import distance, format_dist, fort_details


class MoveToFort(BaseTask):
    SUPPORTED_TASK_API_VERSION = 1

    def initialize(self):
        self.lure_distance = 0
        self.lure_attraction = self.config.get("lure_attraction", True)
        self.lure_max_distance = self.config.get("lure_max_distance", 2000)
        self.ignore_item_count = self.config.get("ignore_item_count", False)

    def should_run(self):
        has_space_for_loot = self.bot.has_space_for_loot()
        if not has_space_for_loot:
            self.emit_event(
                'inventory_full',
                formatted="Inventory is full. You might want to change your config to recycle more items if this message appears consistently."
            )
        return has_space_for_loot or self.ignore_item_count or self.bot.softban

    def is_attracted(self):
        return (self.lure_distance > 0)

    def work(self):
        if not self.should_run():
            return WorkerResult.SUCCESS

        nearest_fort = self.get_nearest_fort()

        if nearest_fort is None:
            return WorkerResult.SUCCESS

        lat = nearest_fort['latitude']
        lng = nearest_fort['longitude']
        fortID = nearest_fort['id']
        details = fort_details(self.bot, fortID, lat, lng)
        fort_name = details.get('name', 'Unknown')

        unit = self.bot.config.distance_unit  # Unit to use when printing formatted distance

        dist = distance(
            self.bot.position[0],
            self.bot.position[1],
            lat,
            lng
        )

        if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
            fort_event_data = {
                'fort_name': u"{}".format(fort_name),
                'distance': format_dist(dist, unit),
            }

            if self.is_attracted() > 0:
                fort_event_data.update(lure_distance=format_dist(self.lure_distance, unit))
                self.emit_event(
                    'moving_to_lured_fort',
                    formatted="Moving towards pokestop {fort_name} - {distance} (attraction of lure {lure_distance})",
                    data=fort_event_data
                )
            else:
                self.emit_event(
                    'moving_to_fort',
                    formatted="Moving towards pokestop {fort_name} - {distance}",
                    data=fort_event_data
                )

            step_walker = StepWalker(
                self.bot,
                self.bot.config.walk,
                lat,
                lng
            )

            if not step_walker.step():
                return WorkerResult.RUNNING

        self.emit_event(
            'arrived_at_fort',
            formatted='Arrived at fort.'
        )
        return WorkerResult.SUCCESS

    def _get_nearest_fort_on_lure_way(self, forts):

        if not self.lure_attraction:
            return None, 0

        lures = filter(lambda x: True if x.get('lure_info', None) != None else False, forts)

        if (len(lures)):
            dist_lure_me = distance(self.bot.position[0], self.bot.position[1],
                                    lures[0]['latitude'],lures[0]['longitude'])
        else:
            dist_lure_me = 0

        if dist_lure_me > 0 and dist_lure_me < self.lure_max_distance:

            self.lure_distance = dist_lure_me

            for fort in forts:
                dist_lure_fort = distance(
                    fort['latitude'],
                    fort['longitude'],
                    lures[0]['latitude'],
                    lures[0]['longitude'])
                dist_fort_me = distance(
                    fort['latitude'],
                    fort['longitude'],
                    self.bot.position[0],
                    self.bot.position[1])

                if dist_lure_fort < dist_lure_me and dist_lure_me > dist_fort_me:
                    return fort, dist_lure_me

                if dist_fort_me > dist_lure_me:
                    break

            return lures[0], dist_lure_me

        else:
            return None, 0

    def get_nearest_fort(self):
        forts = self.bot.get_forts(order_by_distance=True)

        # Remove stops that are still on timeout
        forts = filter(lambda x: x["id"] not in self.bot.fort_timeouts, forts)

        next_attracted_pts, lure_distance = self._get_nearest_fort_on_lure_way(forts)

        # Remove all forts which were spun in the last ticks to avoid circles if set
        if self.bot.config.forts_avoid_circles:
            forts = filter(lambda x: x["id"] not in self.bot.recent_forts, forts)

        self.lure_distance = lure_distance

        if (lure_distance > 0):
            return next_attracted_pts

        if len(forts) > 0:
            return forts[0]
        else:
            return None

My config.json

{
    "auth_service": "google",
    "username": "[email protected]",
    "password": "PASSWORD",
    "location": "Central Park",
    "gmapkey": "KEY",
  "tasks": [
            {
        "type": "HandleSoftBan"
      },
      {
        "type": "UpdateTitleStats",
            "config": {
                "min_interval": 20,
                "stats": ["level_stats", "stardust_earned", "xp_earned", "xp_per_hour", "stops_visited", "pokemon_caught", "uptime"]
            }
      },
      {
        "type": "CollectLevelUpReward"
      },
      {
        "type": "IncubateEggs",
        "config": {
          "longer_eggs_first": true
        }
      },
      {
        "type": "TransferPokemon"
      },
      {
        "type": "EvolvePokemon",
        "config": {
            "evolve_all": "NONE",
            "first_evolve_by": "iv",
            "evolve_above_cp": 1500,
            "evolve_above_iv": 0.8,
            "logic": "or",
            "evolve_speed": 1,
            "use_lucky_egg": false
        }
      },
      {
        "type": "RecycleItems",
        "config": {
          "min_empty_space": 10,
          "item_filter": {
      "1": { "keep" : 100 },
      "2": { "keep" : 20 },
      "3": { "keep" : 100 },
      "4": { "keep" : 0 },
      "101": { "keep" : 0 },
      "102": { "keep" : 0 },
      "103": { "keep" : 0 },
      "104": { "keep" : 100 },
      "201": { "keep" : 0 },
      "202": { "keep" : 0 },
      "301": { "keep" : 20 },
      "401": { "keep" : 0 },
      "402": { "keep" : 0 },
      "403": { "keep" : 0 },
      "404": { "keep" : 0 },
      "501": { "keep" : 0 },
      "602": { "keep" : 0 },
      "603": { "keep" : 0 },
      "604": { "keep" : 0 },
      "701": { "keep" : 75 },
      "702": { "keep" : 0 },
      "703": { "keep" : 0 },
      "704": { "keep" : 0 },
      "705": { "keep" : 0 },
      "801": { "keep" : 100 },
      "901": { "keep" : 100 },
      "902": { "keep" : 100 },
      "1001": { "keep" : 100 },
      "1002": { "keep" : 100 }
          }
        }
      },
      {
        "type": "CatchVisiblePokemon"
      },
      {
        "type": "CatchLuredPokemon"
      },
      {
        "type": "SpinFort"
      },
      {
        "type": "MoveToFort"
      },
      {
        "type": "FollowSpiral",
        "config": {
          "diameter": 4,
          "step_size": 50
        }
      }
    ],
    "map_object_cache_time": 5,
    "forts": {
      "avoid_circles": true,
      "max_circle_size": 50
    },
    "websocket_server": false,
    "walk": 80,
    "action_wait_min": 1,
    "action_wait_max": 2,
    "debug": false,
    "test": false,
    "health_record": false,
    "location_cache": false,
    "distance_unit": "ft",
    "reconnecting_timeout": 5,
    "evolve_captured": "NONE",
    "catch_randomize_reticle_factor": 1.0,
    "catch_randomize_spin_factor": 1.0,
    "logging_color": true,
    "catch": {
      "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" }
    },
    "release": {
      "any": {"keep_best_cp": 1, "keep_best_iv": 1, "logic": "or" }
    },
    "vips" : {
         "any": {"catch_above_cp": 1500, "catch_above_iv": 0.8, "logic": "or" },
    }    
}

nanogirl21 avatar Aug 11 '16 09:08 nanogirl21

Your move to fort config is missing it's config options Example - https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/configs/config.json.example#L67 Yours - { "type": "MoveToFort" },

k4n30 avatar Aug 11 '16 14:08 k4n30

@k4n30 That was my original config.json file and I received the exact same error with that as well. As mentioned in the original post I have modified my config.json file multiple times based on chat/slack support. One of those modifications was to keep the line there and change to the config line to FALSE. I received the same error. Another modification was to remove the config completely (what I posted above) and I am still receiving the same error.

I should probably note that I don't have problems moving to forts or even lured forts. The problem comes when I get to the lured fort (regular forts are fine). The bot crash with the AttributeError: 'NoneType' object has no attribute 'get' error.

Side note: I believe you were in the chat the past few days when I have been asking for help with this and suggest the same thing that is not working.

nanogirl21 avatar Aug 11 '16 16:08 nanogirl21

I also get this error. It happened to me just now when trying to fix a softban. After visiting a pokestop, it crashes.

JoshuaWise avatar Aug 12 '16 00:08 JoshuaWise

No I don't check the help channel you might be confusing me with someone else

I noted you omitted the details from the issue template that would help us to solve your problem, are you able to add the relevant fields from https://github.com/PokemonGoF/PokemonGo-Bot/blob/dev/.github/ISSUE_TEMPLATE.md

Also can you please update to the latest version and see if you're still experiencing the same issue.

k4n30 avatar Aug 12 '16 00:08 k4n30

Mine is suddenly working again. Perhaps it's an issue with the server?

JoshuaWise avatar Aug 12 '16 00:08 JoshuaWise

@JoshuaWise @k4n30 I came here to note that I am no longer having the issue. It fixed itself. I am assuming server issue.

nanogirl21 avatar Aug 12 '16 01:08 nanogirl21