I have a python add-in button shown as follows. It has to make a http request and use the values from the response. But whenever I use requests package, the add-in result in Missing button.

import arcpy
import pythonaddins
import requests

class ButtonClass1(object):
    """Implementation for ZoomButton_addin.button (Button)""" 
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        url = "https://www.linearbench.com/api/azgiv/extent"
        r = requests.get(url = url, verify = False)
        #data = r.json()
        #xmin = data['xmin']
        #ymin = data['ymin']
        #xmax = data['xmax']
        #ymax = data['ymax']
        mxd = arcpy.mapping.MapDocument('current')
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        #ext = arcpy.Extent(xmin,ymin,xmax,ymax)
        ext = arcpy.Extent(45,2,50,5)
        df.extent = ext

According to Esri, it's commonly caused by syntax error.

Anytime a tool or button fails to load and displays Missing on the toolbar instead of the expected icon or name, it is commonly due to a Python syntax error. Recheck your Python script for syntax errors or incorrect inputs to Python functions.

But I tested my code in the ArcMap python window. It works fine. What could be the cause of the problem?

  • I would change this line of code r = requests.get(url = url, verify = False) to r = requests.get(url, verify = False) – enolan Oct 19 '18 at 19:14

To check the syntax of the script in IDLE you could use Run | Check Module to tell you that there is a syntax error and when you click OK it should show you where.

As you commented, in this case you used that technique and discovered that:

It's caused by indention error

Not the answer you're looking for? Browse other questions tagged or ask your own question.