AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

tcpopen(GET) with Redirects/HTTPS
 
 

Hey Bruce, Dave, and the rest of the ChatScript team! I hope things are going well with you all! I wanted to let you know that you now have officially a new WIP convert to ChatScript. It’s been a number of years since I last looked at ChatScript, and what wonderful enhancements you have made…Bravo! I have been wanting to fully localize and enhance my app Back Talk, and ChatScript appears to now have everything I need to accomplish what I need.  I have it pretty much running fully on my server now, but I do have a few questions that I hope you don’t mind me sending your way.  One feature I can’t seem to get working right is my code to scrape the Wiki API.  I’m using the proper “tcpopen(GET” code, but Wiki redirects the api query causing the tcpopen code to fail with an “Tcpopen- HTTP ack code bad 301 T”

Let’s say I want to hit:

en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext;&redirects;=true&exintro;&titles;=robots

but the API redirects to:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext;&redirects;==true&exintro;&titles;==robots

How do I open the https result to avoid the 301 redirect error? (and note that you need to remove the semi-colons the forum is adding to the links above)

Thanks for any/all help as I make this plunge!

 

 
  [ # 1 ]

Sorry for sluggish response, been a bit busy with multiple deadlines. Nominally I presume I need to modify the engine to detect the redirect and auto resubmit to the new address. But in your example that may be an issue because CS is not currently supporting https and your redirect was to an https address.

 

 
  [ # 2 ]

Thank you Bruce. An auto-redirect with HTTPS support would be great as a future enhancement. But, rats. Any other method anyone is aware of to use the Wiki api today? This is pretty powerful stuff for obtaining wonderful bot responses!

 

 
  [ # 3 ]

I’m currently having my offline AI activate curl.exe to download wikipedia contents to a local file, then have it read that. It takes some timing but the least effort.
https://www.chatbots.org/ai_zone/viewthread/2183/
I’m curious what kind of wikipedia-based responses you’re implementing. I can only think to read the first paragraph aloud to a “What is a…?” question as many chatbots seem to do.

 

 
  [ # 4 ]

Yes, but I was trying to avoid creating temp files to extract from. I was hoping to read directly from the source if there was anyway possible.  Don, your Wiki post was the one that got me started down this path so it’s your fault Bruce now gets to make code changes! smile

 

 
  [ # 5 ]

smile Oh I see. Well, in php you could probably load the GET-request to a variable directly, and you can avoid the redirect if you take the plural -s off “robots”. With Curl I had to add a command line argument to disable security certificates before I was able to read from wikipedia’s https.

I would probably try a hack if I had to: Put some non-https php file on my server that retrieves wikipedia’s entry, then tcpopen() that php file. I barely have any online-bot experience though, I’m hoping the others know more.

 

 
  [ # 6 ]

I was hoping! But no, removing the s on robot did not stop the wiki api from redirecting.  And I can’t find any reference in the api to avoid the https. Do you remember what the argument was?

 

 
  [ # 7 ]

This redirects? (I also took out the “redirect=true”)
https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext;&exintro;&titles;=robot

The command line argument I mentioned applies to Curl (“curl.exe—insecure https://www.etc”), it’s not part of wikipedia’s api.

 

 
  [ # 8 ]

Yes, Chatscript doesn’t allow you to put the header “https:// in a tcpopen command, so the en.wikipedia.org/w/api.php…. address unfortunately still redirects to the https://en.wikipedia.org/w/api.php... address causing the 301 error.

 

 
  [ # 9 ]

My answer to this now is in the forthcoming release which supports JSON and the internet using CURL libraries.  They have extensive web protocol support. LIKELY the JSON routines will be more suited to your use than TCPOPEN. At some point I will migrate TCPOPEN to use CURL, but that will not be a high priority task.

 

 
  login or register to react