Link to home
Start Free TrialLog in
Avatar of cb_it
cb_itFlag for United States of America

asked on

coldfusion xml 500 internal server error

Back into some web stuff after about 5 years. Trying to setup a basic xml parse in CF. Geeting a 500 internal server error. Windows 2008 and IIS.

I signed up for the Weather Underground API - I blocked out my API key. IIS is returning a 500 internal server error. ANy ideas??

<cfhttp url="http://api.wunderground.com/api/MyKeyGoesHere/geolookup/conditions/q/IA/07204.xml" method="get">
     <cfhttpparam type="header" name="Accept-Encoding" value="*" />
     <cfhttpparam type="Header" name="TE" value="deflate;q=0">
 </cfhttp>
      <cfset objRSS = xmlParse(cfhttp.filecontent)>
    <CFDUMP var="#objRSS#">
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

You can turn IIS to show detailed errors:

Click the site > Error Pages > Edit Feature settings (on the far right) > Check details errors.

The error is probably the CFHTTP is not returning valid XML in the XMLParse. Try dumping out the cfhttp.filecontent and aborting. Then see what is actually being returned.

Tom
Avatar of cb_it

ASKER

Thanks for the quick reply. I've been away from IIS WAY too long! I turned on the detailed errors.

An error occured while Parsing an XML document.  
Content is not allowed in prolog.  

I did put this xml url into my browser and it does return what looks like a valid xml file.
ok, so the FileContent being returned cannot yet be used in XMLParse() as its not valid.

Could you please do a dump of the FileConent and either screenshot it or copy it here?

or even better share the URL where its happening (if possible)

Tom
Try this little experiment as well from Ben Nadel:

http://www.bennadel.com/blog/1206-Content-Is-Not-Allowed-In-Prolog-ColdFusion-XML-And-The-Byte-Order-Mark-BOM-.htm

This has cropped more than once in my experience with XML and CF. This has sometimes helped.

Tom
Avatar of cb_it

ASKER

Funny, I have that page open in a tab right now! Will try and post back, thanks.
Avatar of cb_it

ASKER

Might be something on their end as I did a dump and got a connection error

ErrorDetail Connect Exception: Connection to http://api.wunderground.com refused  
Filecontent Connection Failure  

hmmm
Avatar of cb_it

ASKER

I paste in my xml url into a browser and get this (only partial copy/paste below)


- <response>
  <version>0.1</version>
  <termsofService>http://www.wunderground.com/weather/api/d/terms.html</termsofService>
- <features>
  <feature>geolookup</feature>
  <feature>conditions</feature>
  </features>
- <location>
  <type>CITY</type>
  <country>US</country>
  <country_iso3166>US</country_iso3166>
  <country_name>USA</country_name>
  <state>NJ</state>
  <city>Roselle Park</city>
  <tz_short>EDT</tz_short>
  <tz_long>America/New_York</tz_long>
  <lat>40.66550446</lat>
  <lon>-74.26724243</lon>
  <zip>07204</zip>
  <magic>1</magic>
  <wmo>99999</wmo>
  <l>/q/zmw:07204.1.99999</l>
  <requesturl>US/NJ/Roselle_Park.html</requesturl>
  <wuiurl>http://www.wunderground.com/US/NJ/Roselle_Park.html</wuiurl>
- <nearby_weather_stations>
- <airport>
- <station>
  <city>Linden</city>
  <state>NJ</state>
  <country>US</country>
  <icao>KLDJ</icao>
  <lat>40.61999893</lat>
  <lon>-74.23999786</lon>
  </station>
- <station>
  <city>Newark</city>
  <state>NJ</state>
  <country>US</country>
  <icao>KEWR</icao>
Hmm possibly their end then. If you could paste the entire XML you have into a text file and attach it here, then we can run it locally and see what it comes up with.

I would hazard a guess its a potential connection problem their end though
hmmm weird I just signed, used my key and your code above and it worked fine?

XMLParse worked perfectly?

Have you definitely signed up for the XML key and not a JSON key? (I don't know if these are seperate)
Avatar of cb_it

ASKER

Format is JSON or XML.

http://www.wunderground.com/weather/api/d/docs?d=data/index

I'm stumped. Works for you and not me!!
Avatar of cb_it

ASKER

I copy/paste their coldfusion json sample from here and get the following error

JSON parsing failure at character 1:'C' in Connection Failure



http://www.wunderground.com/weather/api/d/docs?d=resources/code-samples
What version of CF are you using?
I get the same problem with the JSON method; if you dump the cfhttp.filecontent, you get "Connection Failure" .. so guess that's not working. The XML version still is though.

Silly question but you have put your API key in your code above??
Avatar of cb_it

ASKER

ColdFusion 10,282462
Yep that works for me as well. This page is using your code:

http://www.orangecactus.co.uk/admin/test.cfm

The code:

http://pastebin.com/psy13zyB

Tom
Avatar of cb_it

ASKER

Grrr, thanks for the help. Could be a firewall issue??
Edit Oops... I missed a few responses ;-)  Yes, since it seems connection related it's possible there's a firewall problem.

------------------------------
I copy/paste their coldfusion json sample from here and get the following error

JSON parsing failure at character 1:'C' in Connection Failure

It sounds like there's nothing wrong with the parsing code, the problem is w/your connection. ie If the connection fails you're getting back an error instead of valid xml/json content. So there's nothing to parse. From what Tomarse111 described, his connection is fine. That's why it works for him.

Before you attempt any parsing, dump the cfhttp response and check the status code. It's probably failing (It's a good idea to do that anyway as part of the normal error handling)
<cfdump var="#cfhttp#">

FWIW, I don't have a key, but the JSON string from here parses fine w/CF10
http://www.wunderground.com/weather/api/d/docs?d=data/index&MR=1
Avatar of cb_it

ASKER

Charset [empty string]  
ErrorDetail Connect Exception: Connection to http://api.wunderground.com refused  
Filecontent Connection Failure  
Header [empty string]  
Mimetype Unable to determine MIME type of file.  
Responseheader struct [empty]
 
Statuscode Connection Failure. Status code unavailable.  
Text YES
I hadn't seen all the responses before posting, but .. I tried the JSON example here:

http://www.wunderground.com/weather/api/d/docs?d=resources/code-samples

with the key in Tomarse111's pastebin example, and it worked fine. @Tomarse111 can you try it from your end again?

<cfhttp url="http://api.wunderground.com/api/xxxxxxxx/geolookup/conditions/q/IA/Cedar_Rapids.json" method="get">
     <cfhttpparam type="header" name="Accept-Encoding" value="*" />
     <cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>
<cfdump  var="#cfhttp#">      
<cfset json = deserializeJSON(cfhttp.filecontent)>
<cfdump  var="#json#">
Yep, that JSON version works fine for me as well, with both my Key and the key posted a few comments up. That code however is slightly tuned / different from their example.

http://www.wunderground.com/weather/api/d/docs?d=resources/code-samples&MR=1

Maybe this is where the problem is stemming?

Tom
So just to clarify both the XML and JSON examples posted in this thread, work fine for me.
Avatar of cb_it

ASKER

I'm just stumped, although I love trouble shooting things like this.

Just seems so odd that I can paste the xml url into my browser and it returns valid data, but creating a basic cfm page and it doesnt work. Why would I get a 'Connection failure'. ??
> That code however is slightly tuned / different from their example.

Yeah, I was thinking maybe your extra headers made the difference. But it seems to work even without them... Since it works ok for both of us, I'm still wondering if it's a connection problem on cb_it's end.  @cb_it - What happens if view the JSON url in your browser (instead of cfhttp)?

ie http://api.wunderground.com/api/xxxxxxxx/geolookup/conditions/q/IA/Cedar_Rapids.json
Gah ... I keep missing posts.  Doing too many things at once.

@cb_it - Anything interesting in your log files? Because it really sounds like a firewall problem ... Also are *any* cfhttp requests successful?
What happens when you paste the URL for the XML or JSON from the server that coldfusion is hosted on, i.e. the windows box? Your actual CF server may not be able to connect out to the api.wundergroun.com URL. Try pinging from your server as well.

I'm presuming you are simply copying the URL into you local browser and that CF is running separately to your IDE environment.
Avatar of cb_it

ASKER

Is there a spot in coldfusion to enter a proxy server??
Tomarse111 has it well in hand, so I'm going to leave you guys too it :) I just chimed in to confirm that some else could successfully access the url too, so it might be an environment specific problem.  Later guys!
ASKER CERTIFIED SOLUTION
Avatar of Tomarse111
Tomarse111
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cb_it

ASKER

effing proxy

it works, thanks guys for all the help
Avatar of cb_it

ASKER

Also had to add these 2 lines when using the json example

<cfhttpparam type="header" name="accept-encoding" value="*">
<cfhttpparam type="header" name="te" value="deflate;q=0?">

Found it on this site
http://australiansearchengine.wordpress.com/2009/09/28/cfhttp-connection-failure/
Yeah,  Tomarse111 included those headers in his earlier sample. You may have missed it.

> effing proxy
> it works, thanks guys for all the help

don't you love proxies ... ? BTW, no points for me because I just re-confirmed what Tomarse111 said. He did all the work (setting up an account, examples, etc...). I just enjoy group troubleshooting :)