Extension talk:Math/Archive 2016 to 2024

About this board

https://wikimedia.org/api/rest_v1/ returning code 0 and not 200

14
Nyet (talkcontribs)

Using mediawiki 1.31 and Math extension REL_31

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":)

If i change it to allow code 0:

diff --git a/MathRestbaseInterface.php b/MathRestbaseInterface.php
 index 2dc5d45..5355177 100644
 --- a/MathRestbaseInterface.php
 +++ b/MathRestbaseInterface.php
 @@ -364,7 +364,7 @@ class MathRestbaseInterface {
          */
         public function evaluateRestbaseCheckResponse( $response ) {
                 $json = json_decode( $response['body'] );
 -               if ( $response['code'] === 200 ) {
 +               if ( $response['code'] === 200 || $response['code'] === 0) {
                         $headers = $response['headers'];
                         $this->hash = $headers['x-resource-location'];
                         $this->success = $json->success;
 
 

I get

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem.")

Is the RESTBase server down?

Jdforrester (WMF) (talkcontribs)

Is the RESTBase server down?

No, but maybe the Mathoid service is?

87.123.120.67 (talkcontribs)

My Math extension have been failing with the same error since a few days.

38.140.29.18 (talkcontribs)

I've had this problem too. After some debugging, it appears that PHP's curl was refusing the SSL certificate of https://wikimedia.org/api/rest_ . I downloaded a cacert.pem file and pointed edited the php.ini to point to under under variable curl.cainfo and openssl.cafile. This fixed my problem.

[curl]

curl.cainfo = "C:\PHP7\cacert.pem"

[openssl]

openssl.cafile="C:\PHP7\cacert.pem"

J Ra Rose (talkcontribs)

Since today I have the same issue. Where did you download the cacert.pem file?

2001:B68:16:80:921B:EFF:FE13:C9A2 (talkcontribs)

We have the same issue as OP. Adding certificates to php.ini did not help.

2001:B68:16:80:921B:EFF:FE13:C9A2 (talkcontribs)

Our problems started after a system update. The issue is probably caused by changes in other packages.


2001:B68:16:80:921B:EFF:FE13:C9A2 (talkcontribs)
Johanngan (talkcontribs)

I had the same issues as OP on MediaWiki 1.32. The HTTP responses were coming back just fine (rendered math and everything); the problem was coming from the MultiHttpClient in the core. It parses the HTTP response code from the header with a regex match that's hard coded to look for HTTP/1.x, when in fact my server was receiving an HTTP/2 response. The code 0 was a default that was never overwritten thanks to the failed match.

I found two workarounds that resolved the issue for me.

  1. Change all the checks in MathRestbaseInterface.php to accept a code 0 response.
  2. Go against Do_not_hack_MediaWiki_core and modify the regex in MultiHttpClient to properly match the HTTP/2 response code.
    • I'm pretty sure I only modified one line of code. Here's what I did:
    1. Locate the file MultiHttpClient.php. It should be on the path: <Your MediaWiki root directory>/includes/libs/MultiHttpClient.php.
    2. Search for the line of code that uses preg_match(), in the getCurlHandle method. For me it was on line 390 (MW 1.33), line 392 (MW 1.32).
    3. Change the argument from "/^(HTTP\/1\.[01]) (\d{3}) (.*)/" to "/^(HTTP\/[12](?:\.[01])?) (\d{3}) (.*)/"
      • Just to be clear, here's the diff:
        diff MultiHttpClient_orig.php MultiHttpClient.php
        
        392c392
        < 				if ( preg_match( "/^(HTTP\/1\.[01]) (\d{3}) (.*)/", $header, $matches ) ) {
        ---
        > 				if ( preg_match( "/^(HTTP\/[12](?:\.[01])?) (\d{3}) (.*)/", $header, $matches ) ) {

I ended up going with the second option. It seems like an overhaul of the MultiHttpClient is in the works with T202352, so maybe this issue will resolve itself in future releases.

British Potato (talkcontribs)

Could you describe in a bit more detail what you did to MultiHttpClient? I might go by your second solution as well.

Johanngan (talkcontribs)

Edited my above comment with more details on what I did.

123.51.111.134 (talkcontribs)

I used the Johangan's hack:

  1. Change all the checks in MathRestbaseInterface.php to accept a code 0 response."

and it worked.

When I have created a patch file to use in our docker container, I'll post it as a gist here...

Dloewenherz2 (talkcontribs)

I did what Johangan recommended as well. Here's my rough patch, which "works".

--- MathRestbaseInterface.php	2019-08-09 19:10:54.000000000 -0500
+++ MathRestbaseInterface.php	2019-08-09 19:23:45.000000000 -0500
@@ -8,6 +8,8 @@

 use MediaWiki\Logger\LoggerFactory;

+const WikiMediaServersReturnInvalidErrorCodes = true;
+
 class MathRestbaseInterface {
 	private $hash = false;
 	private $tex;
@@ -382,7 +384,7 @@
 	 */
 	public function evaluateRestbaseCheckResponse( $response ) {
 		$json = json_decode( $response['body'] );
-		if ( $response['code'] === 200 ) {
+		if ( $response['code'] === 200 || WikiMediaServersReturnInvalidErrorCodes ) {
 			$headers = $response['headers'];
 			$this->hash = $headers['x-resource-location'];
 			$this->success = $json->success;
@@ -439,7 +441,7 @@
 	 * @throws MWException
 	 */
 	private function evaluateContentResponse( $type, array $response, array $request ) {
-		if ( $response['code'] === 200 ) {
+		if ( $response['code'] === 200 || WikiMediaServersReturnInvalidErrorCodes ) {
 			if ( array_key_exists( 'x-mathoid-style', $response['headers'] ) ) {
 				$this->mathoidStyle = $response['headers']['x-mathoid-style'];
 			}
@@ -474,3 +476,4 @@
 		throw new MWException( "Cannot get $type. $detail" );
 	}
 }
+
117.251.174.113 (talkcontribs)

I am facing the same issue. The problem seems to be some temporary issue with server. I have implemented retry three times, in case of a failure:

--- a/src/MathRestbaseInterface.php +++ b/src/MathRestbaseInterface.php @@ -172,22 +172,34 @@ class MathRestbaseInterface {

		/** @var MathRestbaseInterface $first */
		$first = $rbis[0];
		$multiHttpClient = $first->getMultiHttpClient();

+ self::batchEvaluateWithRetry( $rbis, $multiHttpClient ); + self::batchGetMathML( $rbis, $multiHttpClient ); + } + + private static function batchEvaluateWithRetry ( array $rbis, MultiHttpClient $multiHttpClient, $retries = 0 ) {

		foreach ( $rbis as $rbi ) {
			/** @var MathRestbaseInterface $rbi */
			$requests[] = $rbi->getCheckRequest();
		}
		$results = $multiHttpClient->runMulti( $requests );

+ $failedRbis = [];

		$i = 0;
		foreach ( $results as $requestResponse ) {
			/** @var MathRestbaseInterface $rbi */
			$rbi = $rbis[$i++];
			try {
				$response = $requestResponse[ 'response' ];

- $rbi->evaluateRestbaseCheckResponse( $response ); + $res = $rbi->evaluateRestbaseCheckResponse( $response ); + if (!$res) { + $failedRbis[] = $rbi; + }

			} catch ( Exception $e ) {
			}
		}

- self::batchGetMathML( $rbis, $multiHttpClient ); + + if (count($failedRbis) > 0 && $retries < 3) { + self::batchEvaluateWithRetry( $failedRbis, $multiHttpClient, $retries + 1 ); + }

	}

	private function getMultiHttpClient() {

Reply to "https://wikimedia.org/api/rest_v1/ returning code 0 and not 200"

Failed to parse. Math extension cannot connect to Restbase.

4
Blyatman9000 (talkcontribs)

I am new to MediaWiki, and I have created private wiki and was able to display math in my wiki pages. However, after having a certain number of equations, I get these error messages:

Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle y=x+1}

The page contains text and about 15 equations spread throughout. The error occurs when I try to add a 16th equation, which causes all the equations to display a similar error. I also simplified the page so that the page just contained numerous lines of <math>0</math>, but it was the same issue.

Can anyone assist me on this issue? I know this error has been discussed many times before, but I couldn't get a proper fix for it.

I am using MediaWiki 1.39.3 and PHP 8.2.0 (apache2handler). In LocalSettings.php, I have simply added wfLoadExtension( 'Math' ) with no other configurations.

Fokebox (talkcontribs)

I often receive such message "Math extension cannot connect to Restbase." Especially if I have a lot of formulas at the page. Is there a way to resolve the problem?

138.100.155.219 (talkcontribs)
Agatnor (talkcontribs)

I also have the same problem of "Math extension cannot connect to Restbase", can someone help me fix it?

Reply to "Failed to parse. Math extension cannot connect to Restbase."
*Surak* (talkcontribs)

I am not sure if I identified the following as true issues, therefore, I didn't dare to change the documentaiton on myself. Maybe one of the devlopers can have a short look here?

In chapter 4 List of significant configuration settings, the table has in rows 3 and 4:

Setting name Default value Description
$wgMathFullRestbaseURL false The math extension gets the default config from the Visual Editor, if available. Details.
$wgMathPreferRestbaseURL true Whether to allow using of internal RESTBase path instead of $wgMathFullRestbaseURL and $wgVisualEditorFullRestbaseURL. Set false if you want to use external RESTBase in any case.

The table would make more sense to me, if the setting name '$wgMathFullRestbaseURL' is replaced by '$wgVisualEditorFullRestbaseURL', since '$wgMathFullRestbaseURL' is already defined in chapter 3.1.1 Mathoid as a service as https://wikimedia.org/api/rest_, and cannot be set to a boolean value at the same time.

Another question in regard to the Details link: It currently refers to MathRestbaseInterface.php#182 ($rbi = $rbis[$i++];). Is the link potentially broken?

Reply to "Documentation issue"

Setup Proxy for curl used by Math extension

1
Cheellaz (talkcontribs)

I am fairly new to MediaWiki, please be kind :)


I have the Math extension installed (version 3.0.0) with the recommended output mode 'mathml', using Mathoid as the default service. My MediaWiki version is 1.39.4.

I receive "Fatal exception of type "MWException" when loading my wiki's page Special:MathStatus (e.g. Special:MathStatus)


In my MediaWiki log I read:

[Math] Start rendering "x^2+\text{a sample Text}" in mode mathml

[http] HTTP start: POST https://wikimedia.org/api/rest_v1/media/math/check/tex

[http] Error fetching URL "https://wikimedia.org/api/rest_v1/media/math/check/tex": (curl error: 28) Timeout was reached

[Math] Tex check failed


It looks like I have a connection issue to the Mathoid service hosted by wikimedia.org.


I must use proxy for all external webrequests in the network my Wiki is hosted.

I have set option $wgHTTPProxy in my Wiki's LocalSettings.php and confirmed this setting took affect by enabling images on my wiki hosted by InstantCommons.

The manual pages for $wgHTTPProxy (Manual:$wgHTTPProxy) states that it sets the proxy for curl.


Does this setting also apply to curl used by the Math extension?


Or do I have to separately configure a proxy for curl used by Math extension? How can I do this?

Reply to "Setup Proxy for curl used by Math extension"

User interface suggestion

1
Joshuardavis (talkcontribs)

Recently at English Wikipedia's Help talk:Displaying_a_formula (sorry, the editor here won't actually let me link), a user raised a reasonable complaint. In Preferences / Appearance / Math, the two radio button options are to render math as LaTeX source or as SVG. The typical user doesn't know what either one is. They just want to see well-typeset math, like in publications. So how about re-wording the second option? Maybe "publication-like notation rendered via SVG"? Or something better! Thanks.

Reply to "User interface suggestion"

Installing math problem

1
1957Harry (talkcontribs)

I have installed Math version 3.0.0 (7fac46b) today, as seen in the Special:Version page( My wiki version 1.37.1). Following the instructions I run the updatescript, my screen show's this:

...collations up-to-date.

...index rc_name_type_patrolled_timestamp already set on recentchanges table.

...rev_page_id index already non-unique.

...pl_namespace, tl_namespace, il_to indices are already non-UNIQUE.

...h


and Its still running.

Is there a so;lution/option to shorten this process??

Reply to "Installing math problem"
Summary by Tacsipacsi

Giving it loads of RAM solved the issue.

Oravela (talkcontribs)

Hi,

I'm trying to understand where the Math extension writes temporary files as I want to check the folder permissions. Can anyone point me in the right direction?

I am basically trying to solve an issue where the rendering fails and when I check Math Status in the special pages on my wiki it shows:

MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools)

Running backend tests for rendering mode MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools).

Test Rendering the input "x^2+\text{a sample Text}" succeeded.

Test Comparing to the reference rendering succeeded.

Test Rendering of a+b in plain MathML mode succeeded.

Test Checking the presence of '+' in the MathML output succeeded.

Test Comparing the generated SVG with the reference failed.

Test Checking if MathML input is supported succeeded.

Test Rendering Presentation MathML sample failed.

Test Checking if the link to SVG image is correct failed.

Backend tests for rendering mode MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools) completed.

As you can see the first failure is where it tries to compare the generated SVG with the reference. I am curious as to whether it is unable to save the generated SVG to the temporary directory.

Hope someone can help me out as I've been trying to solve this for several days now.

Many thanks in advance.

Tacsipacsi (talkcontribs)

The code is quite complicated, but I don’t think it tries to save the image into a temporary directory at all – instead, it reads the reference image from the images/ directory, and compares it with the generated image in memory. Since SVGs are text files, one possible issue may be wrong line ending. Are you on Windows?

Special:MathStatus also seems to log a fair amount of information. Did you enable debug logging (see Manual:$wgDebugLogFile)?

Oravela (talkcontribs)

Hi @Tacsipacsi,

Many thanks for getting back to me.

I have been further investigating and found an example in the logs where the first three math equations in a page fail, but the fourth is successful. The error log shows:

(curl error: 56) Failure when receiving data from the peer

(curl error: 27) Out of memory

(curl error: 27) Out of memory

[http] HTTP complete: code=200 size=133 total=0.167406 connect=0.039775

This leads me to think that the failed to parse error is actually due to a memory issue on my web server. I will post any further updates I have here to hopefully help others that may have issues with the math extension.

If you think there is any there issue causing these errors, of course, please let me know.

Oravela (talkcontribs)

Update.

My log file also showed the following error:

[http] Error fetching URL "https://wikimedia.org/api/rest_v1/media/math/check/tex": (curl error: 6) Couldn't resolve host name

The visible error on the media wiki page looked like:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://en.wikipedia.org/api/rest_v1/":

I tried, but they did not work, the fixes explained by @Johanngan in this discussion topic:

https://www.mediawiki.org/w/index.php?title=Topic:Uo3kkmmop1jj9vhw&topic_showPostId=v2pfwaghxx0fmu0c#flow-post-v2pfwaghxx0fmu0c

What did work was increasing the memory on my web server to 2048MB. This should not have been necessary but it did solve my problem. I hope this may help others who run into the Math extension cannot connect to Restbase error message.

Tacsipacsi (talkcontribs)

Thanks for sharing your solution. I’s indeed strange, 2 GiB is a lot… I’ll now close this thread, but feel free to reopen it if you have anything to add.

$wgMathValidModes are ignored on Mediawiki 1.35.1

2
166.104.144.95 (talkcontribs)

$wgMathValidModes does not forbid user or server to use the excluded options. I tested only on Mediawiki 1.35.1. For example, the below LocalSettings.php allows user to use 'source' or 'png':

wfLoadExtension( 'Math' );
$wgMathValidModes[] = 'mathml';
$wgDefaultUserOptions['math'] = 'mathml';
Kghbln (talkcontribs)

Same here. 1.35.x appears to ignore the settings to the configuration parameter.

Reply to "$wgMathValidModes are ignored on Mediawiki 1.35.1"

configure size of the formuls

1
PetaloAzul (talkcontribs)

hello, at the moment the extension simple math jax is the extension with setting for personalizate the formuls of math and chemistry, the extension have the config $wgSmjScale for change the size of the formuls, the extension math have that config similar?

Reply to "configure size of the formuls"

"Math extension cannot connect to Restbase"

1
Jameshfisher (talkcontribs)
Reply to ""Math extension cannot connect to Restbase""
Return to "Math/Archive 2016 to 2024" page.