[Error] We're having trouble connecting to your site.

[Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Number of replies: 22

Hello everyone,

Hope you are doing great.

I come with issue on my Moodle mobile apps. When I try to accessed and login with correct accounts (link, username and password as well), then when I klik Login: I cannot enter the Moodle and show the notification:

Error: We're having trouble connecting to your site. or like the image attached.

Mungkin gambar teks yang menyatakan 'Error We're having trouble connecting to your site. OK'


Meanwhile, on my admin site - I've tick the Enable web services for mobile devices. And I sure the site is protected with SSL certificate as well.


The SSSL Server Certificate is green for all the item.


If you any advice for ne, appreciated.

Thank you everyone.

Average of ratings: -
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Sunandar,

does this error happen in the official Moodle app (downloaded from Google Play / App Store) or it only happens in a custom app you're building? This question is to determine if it's a problem with the app build or it's a server problem.

If it happens in the official app, maybe your server is returning a 400/500 error in one of the requests done by the mobile app. You can use our webapp (it's for testing purposes) and check the Network requests to see which request is failing.

Cheers,

Dani

In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dani,
Thank you for your response.

Ya, I use in the official Moodle app which I downloaded on Google Play/App Store.
But, I also try with your link webapp for testing, it same issue:

[Cannot Connect]
Error connecting to the server.

Thank you
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Did you check the Network requests to see which request is failing? You can use Chrome DevTools to do that using the Moodle webapp.
In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Oyaa, I've tried.
And the error is:

moodle has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What should I do?
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Isabel Renedo -
Picture of Moodle HQ Picture of Particularly helpful Moodlers
Hi Sunandar,

Please visit the Moodle App FAQ, I think 'I cannot access my site after upgrading to 3.9.5' will be helpful

Kind regards,
Isabel
In reply to Isabel Renedo

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Isabel,
Thank you for your reply.

where can I find the location for "Access-Control-Allow-Origin" on my server?
In reply to Isabel Renedo

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Isabel & Dani,
My moodle it was enabled for web services for mobile devices. And I've check for the SSL its secure as well with green checklist. And then I've check on the token.php, script : Access-Control-Allow-Origin - it was just one item as well.

Please help me, why my moodle cannot connecting with mobile apps?
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Sunandar,

please make sure you're testing the webapp in a browser opened with the right flags as it's explained in this guide.

At server side, this header is usually set in the scripts called by the app, see this file for example.


In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Ok, so I need download Chromium firts right?
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think you can use Chrome too. We only test our webapp with Chromium/Chrome, so it's better if you test it with those browsers instead of using Firefox, Safari or others.
In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dany, I've tried with Chrome, and when I try test with your webapp still error "Error connecting to the server".

When i check the console with inspect element the errors is:

PM CoreFileProvider: Error getting device OS.

Access to XMLHttpRequest at 'mylmsdomain/lib/ajax/service.php?info=tool_mobile_get_public_config' from origin 'https://master.apps.moodledemo.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Failed to load resource: net::ERR_FAILED
Mixed Content: The page at 'https://master.apps.moodledemo.net/login/site?showKeyboard=undefined' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'mydomainlms/lib/ajax/service.php?info=tool_mobile_get_public_config'. This request has been blocked; the content must be served over HTTPS.
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
zone-evergreen.js:2845
Mixed Content: The page at 'https://master.apps.moodledemo.net/login/site?showKeyboard=undefined' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'mydomainlms/lib/ajax/service.php?info=tool_mobile_get_public_config'. This request has been blocked; the content must be served over HTTPS.
scheduleTask @ zone-evergreen.js:2845

What should I do to try your webapp?
Thank you for your help, appreciated.
In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dani, how I can solving this issues with quickly?
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

the script login/token.php is returning something that shouldn't be returning, I guess you modified some Moodle code or you have some kind of firewall or similar adding text to the output.

You can reproduce the issue using this URL in a browser (replacing SITEURL, USERNAME and PASSWORD with the values for your site):

SITEURL/login/token.php?service=moodle_mobile_app&username=USERNAME&password=PASSWORD

You'll see that the response is something like:

1{"token":"...
That number "1" at the beginning shouldn't be there, it's breaking the JSON format. You'll need to check where is it coming from.

Cheers,
Dani
In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Thank you Dani,
I think it's coming from Debugging Message Display, I see there is code 1 in the config.php script.
Let me try to change the code. I will come to you.
In reply to Dani Palou

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
I found this at config.php script

// For Dubugging
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
//

$CFG->directorypermissions = 0777;

require_once(dirname(__FILE__) . '/lib/setup.php');

//There is no php closing tag in this life,
// it is international because it prevents trailing whitespace problems!
"develop/config.php" 43L, 1082C

Maybe I think that is the root of the problem.
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dany,
I think the problem doesn't at that file (I mean config.php). coz I've deactivate the script, still show character number 1 on there (token.php). How I can fix it. Really confused
In reply to Sunandar Prawira

Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I don't know where that character comes from, it's something specific from your site/server so you'll have to debug it yourself, sorry.
In reply to Dani Palou

Odgovor: Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dani,
I think this error appears because one of the plugins is not complete. I found an error when I clicked Edit on the Moodle mobile web service in Plugins --> Web Services --> External Services.

You can see my thread on this also, but it doesn't resolved:
https://moodle.org/mod/forum/discuss.php?d=435525

May you can help?
In reply to Dani Palou

Odgovor: Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
In reply to Sunandar Prawira

Re: Odgovor: Re: [Error] We're having trouble connecting to your site.

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

I'm sorry but that's not my area of expertise, so I can't help you. If you think this "1" comes from a plugin I recommend you to uninstall plugins 1 by 1 until this is fixed, that way you'll know which plugin was causing the error.

Cheers,
Dani
In reply to Dani Palou

Re: Odgovor: Re: [Error] We're having trouble connecting to your site.

by Sunandar Prawira -
Hi Dani,
I hope you are doing well,

I now understand where this problem is coming from.

In the past, I've experienced the missing plugin course_overview (I've written it here: https://moodle.org/mod/forum/discuss.php?d=432767).

My solution was to uninstall the plugin, and then reinstall it.
And that is the reason why I can't login via mobile apps.

I know this cause because I tried to change the name of the course overview folder in my other Moodle (normal Moodle that can login mobile apps), after I changed the name there was missing plugin information. then I rename it back to the beginning. And Moodle runs normally again. but after I try to login via mobile apps, there is the same error, namely "we're having trouble connecting to your site."

This is the cause. I don't understand why this can happen, even though I have reinstalled the plugin and no plugins are missing.

Dani do you have a solution for this?