<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462044#M36172</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had an open ticket with ESRI, but it was not resolved.&amp;nbsp; I'm still trying to figure it out.&amp;nbsp; I think it might be something with the web adapter, but that's just a guess.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Aug 2019 14:18:09 GMT</pubDate>
    <dc:creator>BennettMorris</dc:creator>
    <dc:date>2019-08-28T14:18:09Z</dc:date>
    <item>
      <title>UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462037#M36165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recently got a new work computer and I have a Juypter notebook that I have been using for some time and it's no longer working.&amp;nbsp; My python code logs into our Portal so I can run other reports.&amp;nbsp; I can log onto AGOL using this script, but not our Portal any more.&amp;nbsp; Here is the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;from IPython.display import display&lt;BR /&gt;from getpass import getpass&lt;BR /&gt;import sys&lt;BR /&gt;import datetime&lt;BR /&gt;import time&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ArcGISwebsite = input("Enter ArcGIS Portal / AGOL URL: ")&lt;BR /&gt;username = input("Enter user name: ")&lt;BR /&gt;password = getpass("Enter password: ")&lt;BR /&gt;g = GIS(ArcGISwebsite, username, password)&lt;/P&gt;&lt;P&gt;if g.properties.isPortal == True:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;print("\nConnected to: {}\n\nConnected as: {}".format(g.properties.name + " (" + g.properties.portalHostname +")", g.users.me.username))&lt;BR /&gt;else:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;print("\nConnected to: {}\n\nConnected as: {}".format(g.properties.name + " (" + g.properties.urlKey + "." + g.properties.customBaseUrl +")", g.users.me.username))&lt;BR /&gt;pass&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I receive the "UnboundLocalError: local variable 'resp' referenced before assignment" at "&lt;SPAN style="background-color: #f6f6f6;"&gt;g = GIS(ArcGISwebsite, username, password)".&amp;nbsp; I'm running Windows 10 Pro, ArcGIS Pro 2.3.3, ArcMap 10.7. Any help would be greatly appreciated.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2019 13:35:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462037#M36165</guid>
      <dc:creator>BennettMorris</dc:creator>
      <dc:date>2019-05-29T13:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462038#M36166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We have&amp;nbsp;the same problem.&amp;nbsp; We have tracked it down to requests being made to the server in connection.py of the ArcGIS rest API.&amp;nbsp; The parameter to set the response to return JSON (f=json) is being ignored so when the python tries to parse the JSON it fails as it is HTML.&amp;nbsp; However, this is hidden by the outer try catch.&amp;nbsp; No idea why the parameter is being ignored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we hit the endpoint from postman or any other tool the parameter is respected and the server returns json.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2019 16:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462038#M36166</guid>
      <dc:creator>MikeButt</dc:creator>
      <dc:date>2019-06-04T16:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462039#M36167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did you change the connection.py file so that it does work?&amp;nbsp; I can&amp;nbsp;login to my Portal (using the code above) by using the admin connection&amp;nbsp;&lt;A href="https://FQDN:7443/arcgis"&gt;https://FQDN:7443/arcgis&lt;/A&gt;&amp;nbsp;and then using the builtin original admin account and password.&amp;nbsp; I have a ticket with ESRI about this too.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2019 16:36:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462039#M36167</guid>
      <dc:creator>BennettMorris</dc:creator>
      <dc:date>2019-06-05T16:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462040#M36168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bennett,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We added some debug info into connection.py to check what it was doing and noticed it was returning HTML. Our infrastructure people suggested using the admin connection and FQDN and it worked. We now believe it might be something to do with the url in our load balancer being different to our portal context URL.&amp;nbsp; We are still investigating though.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2019 19:46:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462040#M36168</guid>
      <dc:creator>MikeButt</dc:creator>
      <dc:date>2019-06-05T19:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462041#M36169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was on the phone with ESRI yesterday and the issue is with Microsoft Single Sign On (SSO) and the DNS alias for our ArcGIS Enterprise.&amp;nbsp; If I use &lt;A href="https://FQDN/PortalWebAdapter"&gt;https://&amp;lt;ActualServerName.Domain.com&amp;gt;/&amp;lt;PortalWebAdapter&lt;/A&gt;&amp;gt; it works with my Microsoft active directory account information and SSO, but if I use &lt;A href="https://&amp;lt;DNSalias.Server.com/&amp;lt;PortalWebAdapter&amp;gt;"&gt;https://&amp;lt;DNSalias.Server.com/&amp;lt;PortalWebAdapter&amp;gt;&lt;/A&gt;&amp;nbsp;it doesn't work.&amp;nbsp; Something with the DNS alias and the Python API.&amp;nbsp; I'll let you know what ESRI comes back with.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:55:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462041#M36169</guid>
      <dc:creator>BennettMorris</dc:creator>
      <dc:date>2019-06-07T13:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462042#M36170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Running into what I think is the same problem - did anyone ever get back to you?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2019 21:27:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462042#M36170</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2019-07-10T21:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462043#M36171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I started having this issue when I took the GetParameterAsText away from a parameter that was defined as an output, derived parameter.&amp;nbsp; To be clear, I started writing this script as having a user defined output parameter for an Excel file output, but then figured it would be better to have it as a defined output parameter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the top of my script I always had this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Out_Excel_File = arcpy.GetParameterAsText(1)
 if Out_Excel_File == '#' or not Out_Excel_File:
 Out_Excel_File = "\\\\w-gis-portal\\e$\\Projects\\DRT\\InExcel_Layer_TableToExcel.xls" # provide a default value if unspecified
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But at the bottom of my script I started using this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy.TableToExcel_conversion(InExcel_Layer, Out_Excel_File)
arcpy.SetParameterAsText(1, Out_Excel_File)&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I figured I didn't need the first 2 lines where I set Out_Excel_File at the top of the script, and I remarked them out.&amp;nbsp; But doing that triggered an 'UnboundLocalError'.&amp;nbsp; Resetting them as active code allowed the script to run without error though, so I'm moving forward with what you see here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps someone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:32:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462043#M36171</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2021-12-11T20:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462044#M36172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had an open ticket with ESRI, but it was not resolved.&amp;nbsp; I'm still trying to figure it out.&amp;nbsp; I think it might be something with the web adapter, but that's just a guess.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2019 14:18:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/462044#M36172</guid>
      <dc:creator>BennettMorris</dc:creator>
      <dc:date>2019-08-28T14:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: UnboundLocalError: local variable 'resp' referenced before assignment error using Juypter Notebook</title>
      <link>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/1015441#M59478</link>
      <description>&lt;P&gt;All variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the global symbol table, and then in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced.&lt;/P&gt;&lt;P&gt;The unboundlocalerror: local variable referenced &lt;A href="http://net-informations.com/python/err/local.htm" target="_self"&gt;before assignment&lt;/A&gt; is raised when you try to use a variable before it has been assigned in the local context. Python doesn't have variable declarations , so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 06:38:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unboundlocalerror-local-variable-resp-referenced/m-p/1015441#M59478</guid>
      <dc:creator>warrenfel</dc:creator>
      <dc:date>2021-01-11T06:38:51Z</dc:date>
    </item>
  </channel>
</rss>

