Problem with Simple HTML DOM Error Handling - simple-html-dom

I have list of website which I am passing to function doScrape() this function creates SimpleHtmlDom object and load the url passed to it as a argument.
But when scraper is in progress one url can't be loaded and PHP throws following exception
Warning: file_get_contents(http://www.somesite.com) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in F:\xampp\htdocs\scraping\scraper\simple_html_dom.php on line 850
Due to this error entire scraper stops working. How to handle this exception and keep scraper running event there is an error.

You can do something like this:
$data = #file_get_contents(http://www.somesite.com);
if($data){
//Ok
}else{
//Error
}

Related

Error: getaddrinfo ENOTFOUND undefined on a specific page

We use next.js with knex.js as query builder, in all pages everything is OK except in one page that we have ISR aka getStaticPaths and in that method we get the following error whenever we try to execute a query, but in other pages that do not have getStaticPaths everything works fine:
Server Error
Error: getaddrinfo ENOTFOUND undefined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
GetAddrInfoReqWrap.onlookup [as oncomplete]
node:dns (71:26)
no more info is provided anywhere else. as it is shown in the error message, the database host is undefined but why it read correctly everywhere except in getStaticPaths??
Turns out we had this experimental feature tuned on in next.config.js, when it is turned on .env variables are all undefined and not loaded correctly inside getStaticPaths but once the getStaticProps is called everything is OK, I do not know the reason for this, but turning workerThreads off solved the problem:
experimental: {
workerThreads: false //fixed the problem
},

What does requests.get("url address").raise_for_status() perform in requests package?

import requests
from requests.exceptions import HTTPError
url = 'https://httpbin.org/'
try:
response = requests.get(url) #get method of http will retreive all the data from specific url
# If the response was successful, no Exception will be raised
print(response.status_code) #to know the http status code of requested url
response.raise_for_status() #what does this line do
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}') #to handle any kind of
error Exception class is the main class for all kinds of exceptions
else:
print('Success!')
raise_for_status() returns an HTTPError object if an error has occurred during the process. It is used for debugging the requests module and is an integral part of Python requests. Python requests are generally used to fetch the content from a particular resource URI
https://www.geeksforgeeks.org/response-raise_for_status-python-requests/#:~:text=raise_for_status()%20returns%20an%20HTTPError,from%20a%20particular%20resource%20URI.

Symfony2: __toString() must not throw an exception

I am deploying my Symfony2 application, but I am getting the following error:
FatalErrorException in classes.php line 0:
Error: Method Symfony\Component\HttpFoundation\Request::__toString() must not throw an exception
Apache is slightly more descriptive, stating something about Monolog:
PHP Fatal error: Method Symfony\\Component\\HttpFoundation\\Request::__toString() must not throw an exception in /my/path/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php on line 0
It is also the only thing It is not clear to me how this is happening. Dev-environment on my local machine is running fine.
I have tried to clear the prod cache, the composer cache and restarted apache service. I also did a fresh "composer install" after clearing its cache.
Anyone has an idea how this can be solved? Am running Symfony v2.7.4.
You should to check your $_COOKIE or $_SESSION for example;
The trouble is you could have array value in $_COOKIE, so on your debug environment you could fall into the following situation:
Debug::enable() //see, i don't exclude E_NOTICE here
$request = Request::createFromGlobals();
echo $request->__toString();
//so, from now you've got your Exception because of
//Debug package converts E_NOTICE to Fatal
//which turns into Exception
So if you want to fix this trouble you need to:
find the real reason of exception triggering (notice, deprecated, strict message, etc)
exclude it from Debug: Debug::enable(~E_NOTICE);
OR just remove (string)$request from your code if possible;
see Request code:
//part of __toString() method
foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
}

Errors prevented isopacket load: While loading isopacket `constraint-solver`: Cannot call method 'slice' of null

When launching my meteor app with the following command:
MONGO_URL="mongodb://localhost:27017/vision-test" PORT=8282 ROOT_URL="sertal.esb.local:8383" meteor -p 8383
I get following error:
Errors prevented isopacket load:
While loading isopacket `constraint-solver`:
packages/meteor/url_server.js:11:1: Cannot call method 'slice' of null
at Meteor.absoluteUrl.options (packages/meteor/url_server.js:11:1)
at <runJavaScript-2>:1109:4
at <runJavaScript-2>:1194:3
The same error appears when I use the parameters to run the built application.
the ROOT_URL="sertal.esb.local:8383" parameter is missing the http:// part. The http:// or https:// part of the ROOT_URL is mandatory

Fatal error when copying wordpress site from server to localhost

I've been trying to create a local copy of this wordpress site - click4taps.co.uk. But even though everything seems to run pretty much fine on the server, on localhost I am getting these code errors, I would have maybe expected a database error if I had forgot something in the setup. I'm not super good at php but I can't see anything that out of place in the code the error specifies.
Here is the error message I receive when trying to launch the site in localhost:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'woocommerce_layered_nav_init' not found or invalid function name in C:\Program Files (x86)\Ampps\www\click4taps\wp-includes\plugin.php on line 406
Fatal error: Call to undefined function is_product() in C:\Program Files (x86)\Ampps\www\click4taps\wp-content\themes\bazar\theme\plugins\woocommerce-ajax-layered-nav\init.php on line 59
Any feedback on this would be very helpful thanks
Activate your woocommerce plugin

Resources