|
POST
|
Will, Why would I not search the cat field? Shouldn't I be able to search either field? This validates, but displays no results for "Battery": var cat = $feature.USER_Categ
var key = $feature.USER_Keywo
if (cat == "Appliance Recycling;"){
if (key == "Air Conditioner;Appliance;Dishwasher;Dryer;Oven;Refrigerator;Stove;Washer;Water Heater;"){
return "Appliances"}
}
if (cat == "Asbestos Info / Removal Service;"){
if (key == "Asbestos;"){
return "Asbestos"}
}
if (cat == "Automobile and Boat Reuse Recycling;"){
if (key == "Airplane;Automobile;Boat;Car;Recreation Vehicle;RV;Truck;"){
return "Automobile & Boat"}
}
var batteries = ["Batteries","Disposable Batteries","Household Hazardous Waste (HHW)","Rechargeable Battery"]
for (var batteryType in batteries){
if(Find(batteryType,cat) >=0) {
return ("Battery")
}
} Oddly enough, when I replace cat with key a symbol is created for "Battery". But, the USER_Keywo and USER_Categ fields do not have any of these unique values I'm searching for: var batteries = ["Batteries","Disposable Batteries","Household Hazardous Waste (HHW)","Rechargeable Battery"]
for (var batteryType in batteries){
if(Find(batteryType,key) >=0) {
return ("Battery")
}
} Ben Turrel Am I doing something wrong or is the Arcade Find Function not working the way it should?
... View more
06-22-2020
12:02 PM
|
0
|
8
|
6848
|
|
POST
|
Well, that's just a graphic I did in Inkscape meant to visualize how I'd ultimately like the features to be grouped. I'm looking for a way to group both the USER_Keywo and USER_Categ fields that have similar unique values using Python. Because right now when I turn on labels I have to (1) choose one of the two fields and (2) there are way too many labels. Make sense?
... View more
06-20-2020
03:19 PM
|
0
|
11
|
4051
|
|
POST
|
Xander Bakker, Thanks for the reply. The whole table has 600+ records. Here's a screenshot of both fields. To reiterate, is there a pythonic way to group these features like so, for example?
... View more
06-18-2020
09:12 AM
|
0
|
13
|
4051
|
|
POST
|
I'm working with a table with tons of unique values crammed into a field. Is there a pythonic way to group unique values from multiple attribute fields? That way I'd have one symbol for its respective values instead of there being repetitive values. So, i'd like the table to be organized into something like this: I'm able to do something similar with Arcade, but it's limited. How To: Group unique values from multiple attribute fields in ArcGIS Pro Creating a list in Arcade can be verified in the Expression builder, but there are no results. My thread using Arcade: Arcade If Statement for Multiple Unique Values
... View more
06-17-2020
09:58 AM
|
0
|
15
|
6124
|
|
POST
|
Thank you. That was it! Something else. The URLs are in a list. Is there an easy way to identify the URL that threw the error? I'm starting a new thread here: https://community.esri.com/message/933511-request-module-try-except-error
... View more
06-08-2020
10:00 AM
|
0
|
0
|
9191
|
|
POST
|
What do you do when you catch a Requests exception and you want to identify the URL that caused it? This script loops through a list of URLs and scrapes certain text. If one of the URLs fail in any way I catch it the Try Except block. All I can do now is print the "request error" string. for url in urls: #iterate through list of URLs
try:
#download the homepage
response = requests.get(url)
#parse the downloaded homepage and grab all text
soup = BeautifulSoup(response.text, "lxml")
#find sought after text
item = soup.find(string=re.compile("Grab and Go")) if soup.find(string=re.compile("Grab and Go")) else "N/A"
print(item)
#catch any request error
except requests.exceptions.RequestException:
print("request error") How can I identify the URL causing that error? Maybe something like: except requests.exceptions.RequestException:
print("request error: {}".format(#URL that caused error))
... View more
06-08-2020
09:59 AM
|
0
|
1
|
3782
|
|
POST
|
Joshua, OK, thanks. I tried that. But, I got the same errors in the same order as before. for url in urls:
#download the homepage
response = requests.get(url, headers=headers)
#parse the downloaded homepage and grab all text
soup = BeautifulSoup(response.text, "lxml")
try:
item = soup.find(string=re.compile("Grab and Go")) if soup.find(string=re.compile("Grab and Go")) else "N/A"
print(item)
except requests.exceptions.RequestException as error:
print('there is a requests error')
... View more
06-05-2020
07:17 AM
|
0
|
2
|
9191
|
|
POST
|
I'm using beautifulsoup to scrape a list of URLs for Covid-19 info which in turn is used to update our ArcGIS Hub page. Once in a while, a URL is broke and I get a bad handshake error. I want my script to handle this then move on. Currently, there is one URL in the list that is broke, and that one is causing the error(s) here. I tried the following exception block on these errors to no avail. I also tried these approaches to no avail: while loop except requests.exeptions.SSLError as error: except...
print("error") try:
item = soup.find(string=re.compile("Grab and Go")) if
soup.find(string=re.compile("Grab and Go")) else "N/A"
print(item)
except (OpenSSL.SSL.Error, ssl.SSLError, urllib3.exceptions.MaxRetryError,
requests.exceptions.SSLError) as error:
print(error)
break Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 456, in wrap_socket
cnx.do_handshake()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\OpenSSL\SSL.py", line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\OpenSSL\SSL.py", line 1647, in _raise_ssl_error
_raise_current_error()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
conn.connect()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connection.py", line 344, in connect
ssl_context=context)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\util\ssl_.py", line 347, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 462, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\util\retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.cm201u.org', port=443): Max retries exceeded with url: /news_/free_breakfast___lunch_pick-up_days (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pathtofile", line 33, in <module>
response = requests.get(url, headers=headers)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.cm201u.org', port=443): Max retries exceeded with url: /news_/free_breakfast___lunch_pick-up_days (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
... View more
06-04-2020
12:45 PM
|
0
|
4
|
9477
|
|
POST
|
Thanks Joe, I ended up creating multiple fields for instances with multiple departments in one building. Here's the source. I'll a mark yours correct to close this thread, and it seems like a good idea.
... View more
05-15-2020
08:58 AM
|
2
|
0
|
1348
|
|
POST
|
What's a good way to put a list of names in one polygon feature? For example, I'm creating a County Facilities layer. There are cases when you have multiple departments in the same building. I don't want separate polys for these departments, but be able to label them from the same poly.
... View more
05-14-2020
01:59 PM
|
0
|
2
|
1398
|
|
POST
|
That was it! I took out the white spaces in the text file and then ran it again. It now prints all the URLs. For some reason, though, it's only writing the very last URL to file? The write function is not in the for loop, so why would it not be writing all the URLs? #convert text file into a list
with open(txtfile) as f:
x = (list(map(str.strip ,f.readlines())))
for i in x:
#Request the URL
response = requests.get(i)
#see if the URL has been correctly encoded print(r.url)
r_url = response.text
#parse the downloaded homepage to get a beautifulsoup object
new_xml = BeautifulSoup(r_url, features = "xml").prettify()
#write new list to file in your directory
with open(r'C:\Users\jpilbeam\USPSAPIWCHDUpdateAll_II.txt', "w") as api_list:
api_list.write(new_xml)
api_list.close
... View more
04-13-2020
08:47 AM
|
0
|
1
|
49853
|
|
POST
|
Yes, that's exactly how they look in the text file. I just looped through the text file without passing to requests and they were read correctly. They look fine. But, good call on the spaces between the URLs. I'll take the spaces out and try again.
... View more
04-13-2020
07:52 AM
|
0
|
2
|
49853
|
|
POST
|
Thanks! That was it. There's a problem now with the URL in this script. I've posted another question about here: https://community.esri.com/thread/251431-missingschema-invalid-url-no-schema-supplied
... View more
04-13-2020
07:15 AM
|
0
|
0
|
2739
|
|
POST
|
Using Python 3.6.9, I'm making requests with Requests by calling URLs from a text file. I put five of them here, for example. The URLs are all valid. https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>2001 Gardner Cir W</Address1><Address2></Address2><City>Aurora</City><State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>2427 Oakfield Dr</Address1><Address2></Address2><City>Aurora</City><State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>2451 Avalon Ct</Address1><Address2></Address2><City>Aurora</City><State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>2516 Hillsboro Blvd</Address1><Address2></Address2><City>Aurora</City><State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>2623 Shenandoah Ct</Address1><Address2></Address2><City>Aurora</City><State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest> What I intend it to do is iterate the list of URLs and request each one in the for loop. Then it prints out the BeautifulSoup object. It looks like an XML when it's printed which is what I want. While debugging, I see it loops once and prints the first URL as desired, but then throws an error at the top of the for loop. I don't see what's wrong with the URL? ''' (1) putting the URLs one by one in the browser, (2) get the resulting XMLs,
and (3) listing these XMLs as text in a .txt file '''
import requests
from bs4 import BeautifulSoup
txtfile = r'C:\Users\jpilbeam\USPSAPIWCHDUpdateAll.txt'
#convert text file into a list
with open (txtfile) as f:
x = (list(map(str.strip ,f.readlines())))
for i in x:
#Request the URL
response = requests.get(i)
#see if the URL has been correctly encoded print(r.url)
r_url = response.text
#parse the downloaded homepage to get a beautifulsoup object
new_xml = BeautifulSoup(r_url, features = "xml").prettify()
print(new_xml) Error: >>>
[Dbg]>>>
<?xml version="1.0" encoding="utf-8"?>
<AddressValidateResponse>
<Address>
<Address2>
2001 GARDNER CIR W
</Address2>
<City>
AURORA
</City>
<State>
IL
</State>
<Zip5>
60503
</Zip5>
<Zip4>
6213
</Zip4>
</Address>
</AddressValidateResponse>
Traceback (most recent call last):
File "\\gisfile\GISstaff\Jared\Python Scripts\ArcGISPro\CallToFromUSPS_II.py", line 27, in <module>
response = requests.get(i)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 519, in request
prep = self.prepare_request(req)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 462, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\models.py", line 313, in prepare
self.prepare_url(url, params)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\models.py", line 387, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '': No schema supplied. Perhaps you meant http://?
>>>
... View more
04-13-2020
07:14 AM
|
0
|
4
|
51811
|
|
POST
|
This gets one URL and prints it in XML format. import requests
from bs4 import BeautifulSoup
url = r'''https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=
<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>
2451 Avalon Ct</Address1><Address2></Address2><City>Aurora</City>
<State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>'''
#get the webpage
response = requests.get(url)
#see if the URL has been correctly encoded
r_url = response.text
#parse the downloaded page to get a beautifulsoup object
new_xml = BeautifulSoup(r_url, features = "xml").prettify()
print(new_xml) >>>
<?xml version="1.0" encoding="utf-8"?>
<AddressValidateResponse>
<Address>
<Address2>
2451 AVALON CT
</Address2>
<City>
AURORA
</City>
<State>
IL
</State>
<Zip5>
60503
</Zip5>
<Zip4>
8574
</Zip4>
</Address>
</AddressValidateResponse>
>>> But, I have a list of URLs that need to be printed in XML format. Using this list how can I pass one item at a time into requests.get()? Link to text file. #text file that has all the URLs
txtfile = r'C:\Users\jpilbeam\USPSAPIWCHDUpdateAll.txt'
#convert text file into a list
with open (txtfile) as f:
x = (list(map(str.strip ,f.readlines())))
... View more
04-11-2020
09:23 AM
|
0
|
2
|
2787
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|