Calling Web Page from python addin

2724
3
10-25-2013 04:46 AM
LarryWhite
New Contributor II
I am using either one the following statements to call a url from a python addin using a thread.
#os.startfile(url)
#webbrowser.open(url,new=0)

Both work with default browsers are either chrome or firefox. The problem it crashes ArcMap when MS Explorer 9 is the default browser. Anyone ran across this? Any suggestions?

Larry E. White
GIS Analyst/Programmer
West Virginia Department of Environmental Protection
Tags (2)
0 Kudos
3 Replies
LarryWhite
New Contributor II
The uncommented code works:
this works:



     # this works for explorer
     ie = webbrowser.get('c:\\program files\\internet explorer\\iexplore.exe')
     ie.open(url)




I am using either one the following statements to call a url from a python addin using a thread.
#os.startfile(url)
#webbrowser.open(url,new=0)

Both work with default browsers are either chrome or firefox. The problem it crashes ArcMap when MS Explorer 9 is the default browser. Anyone ran across this? Any suggestions?

Larry E. White
GIS Analyst/Programmer
West Virginia Department of Environmental Protection
0 Kudos
JasonScheirer
Occasional Contributor III
os.startfile and webbrowser.open use COM to do their thing, and they expect the COM runtime to be initialized differently from how ArcGIS does it. You can get around it by calling the function in a different thread.
def open_browser(url):
    import threading
    import webbrowser
    threading.Thread(target=webbrowser.open, args=(url,)).start()
0 Kudos
MicahBabinski
Occasional Contributor III

I tried several different solutions and this one worked for me! Thanks all.

0 Kudos