1

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?

closed as off-topic by user2856, Kadir Şahbaz, Jochen Schwarze, Evil Genius, whyzar Oct 17 '18 at 12:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – user2856, Kadir Şahbaz, Jochen Schwarze, Evil Genius, whyzar
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
2

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.