Newbie problem with urllib.request.urlopen
MRAB
python at mrabarnett.plus.com
Tue Sep 26 11:45:28 EDT 2017
On 2017-09-26 16:31, berniejconnors at gmail.com wrote:
> Hello,
>
> My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run?
> -----------------------
> from urllib.request import urlopen
>
> with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn:
> print(conn)
> -----------------------
> Thanks,
> Bernie.
>
Check the quotes.
The argument you're passing to urlopen is:
'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120''
which is actually:
'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='
75385120 ''
A string, then an int, then another string.
I think you mean:
'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID="75385120"'
More information about the Python-list
mailing list