Sentry (Django) Configuration issue - SENTRY_ALLOW_ORIGIN - python

I'm having issues with Sentry running on my internal server. I walked through the docs to get this installed on a Centos machine. It seems to run, but none of the asynchronous javascript is working.
Can someone help me find my mistake?
This is what Chrome keeps complaining about:
XMLHttpRequest cannot load
http://test.example.com/api/main-testproject/testproject/poll/. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://test.example.com:9000' is therefore not allowed
access.
I'm new to Django, but I am comfortable with python web services. I figured there was surely a configuration I missed. I found something in the docs referring to a setting I should use; SENTRY_ALLOW_ORIGIN.
# You MUST configure the absolute URI root for Sentry:
SENTRY_URL_PREFIX = 'http://test.example.com' # No trailing slash!
SENTRY_ALLOW_ORIGIN = "http://test.example.com"
I even tried various paths to my server by using the fully qualified domain name, as well as the IP. None of this seemed to help. As you can see from the chrome error, I was actively connected to the domain name that was throwing the error.

I found my issue. The XMLHttpRequest error is showing that port 9000 is used. This needs to be specified in the SENTRY_URL_PREFIX.
SENTRY_URL_PREFIX = 'http://test.example.com:9000'
edit:
I even found this answer listed in the FAQ:
https://docs.getsentry.com/on-premise/server/faq/

Related

AADSTS90102 error when using django-microsoft-auth for SSO with Azure AD

I followed the steps in this tutorial to enable SSO with Azure Active Directory for the admin portion (to start) of my Django app:
https://django-microsoft-auth.readthedocs.io/en/latest/usage.html
Navigating to /admin yields this page, which is good:
Clicking Microsoft brings up this new window:
The important error seems to be:
AADSTS90102: 'redirect_uri' value must be a valid absolute URI.
In this window, I used the browser console and found that a GET request was being made like this:
https://login.microsoftonline.com/50ce...90ac7/oauth2/v2.0/authorize?response_type=code&client_id=f4...27&redirect_uri=https,https://example.org/microsoft/auth-callback/&s...
Note the redirect_uri=https,https://.... It seems like that leading "https," is superfluous and is causing the problem. Any ideas where that could be coming from?
In my Azure app, the redirect URI is set to https://example.org/microsoft/auth-callback/:
I'm using Python 3.9.6, Django 3.2, django-microsoft-auth 2.4.0, NGINX 1.18.0, uvicorn 0.14.0
I've searched for help on this and haven't found anything relevant to my situation. Thanks in advance!
Based on the SO Thread Reference.
Use http as the redirect URI instead of https to resolve the issue in most cases.
use
http://localhost:8080/microsoft/auth-callback/
Instead of
https://localhost:8080/microsoft/auth-callback/
If there is a option,
Use localhost:8080 into the table django_site
Reference SO Thread: django-microsoft-auth : The provided value for the input parameter 'redirect_uri' is not valid
As you think, the first https is superfluous, you just need to delete it.
https://login.microsoftonline.com/50ce...90ac7/oauth2/v2.0/authorize?response_type=code&client_id=f4...27&redirect_uri=https://example.org/microsoft/auth-callback/&s...
By the way, I think there is no problem with the redirect_uri you set in the Azure portal.
I guess it is a problem of the redirecting URL. The example URL is coming from django site table. So first of all you need to enable the site:
#in settings.py
SITE_ID = 1
Afterwards you can go to the admin interface and set the url of the site to the correct domain. From my experience I know that it won't work without that.

Python Django /w Microsoft Graphs - I keep getting value error "state missing from auth_code_flow"

Python Django /w Microsoft Graphs -
I'm following this Microsoft Tutorial for building Django apps with Microsoft Graph (using it on my existing Django webapp), and I am having an issue with authentication: https://learn.microsoft.com/en-us/graph/tutorials/python
I'm on the step 'Add Azure AD authentication' and, after implementing,
I hit the sign in button and enter credentials...and I keep getting value error "state missing from auth_code_flow".
The "callback" method is only making it to result=get_token_from_code(request) and then fails.
Here is the get_token_from_code method:
def get_token_from_code(request):
cache = load_cache(request)
auth_app = get_msal_app(cache)
# Get the flow saved in session
flow = request.session.pop('auth_flow', {})
result = auth_app.acquire_token_by_auth_code_flow(flow, request.GET)
save_cache(request, cache)
return result
What I'm trying to do is eventually access excel online from my webapp.
Any help is greatly appreciated!
I just had this issue and resolved it. It is one of these two things:
You are starting out at 127.0.0.1:8000 and then when you're redirected you're at localhost:8000, which is a different domain. The sessions aren't remembered from one domain to the other. The solution is to start out on localhost:8000 so that the session persists across login.
Your browser is using super-strict cookie settings. Microsoft Edge appears to default to this mode on localhost and 127.0.0.1. There is a lock or shield icon in or near your address bar that lets you relax the restrictions on your cookie settings.
Try one or both of these and you should succeed.
I'm a beginner coder, so i'm pretty sure im just circumventing around the error. But replacing the website URL with http://localhost:8000/# and re running it somehow got around the error. maybe that could be of some use.
If you are running on chrome, rather than running application on http://127.0.0.1:8000 run it on http://localhost:8000, because chrome isn't saving the cookies when the ip address is being used.

DisallowedHost error not going away when adding IP address to ALLOWED_HOSTS

If I set ALLOWED_HOSTS = ['*'] I am able to make a succesfull call, however this seems dangerous and counterintuitive.
When I set ALLOWED_HOSTS to the recommended string, it fails. How to fix this?
Since you've tagged your post with AWS, I assume the host in question is an AWS EC2 instance. If so, try put in your EC2 private IP or your full domain instead, like:
['ip-XX-XX-XX-XX.XX-XXX-X.compute.internal']
OR
['.yourdomain.com']
The preceding . in your domain name represents a wildcard, as described in Django's docs
I encountered this and found the reason. There were 2 different tabs which were running server. For test reasons I just started server in another tab. Django doesn't warn in the second tab. So your requests are most probably falling to the another tab running the server.

SOLR mysolr pysolr Python 401 reply

If there is someone out there who has already worked with SOLR and a python library to index/query solr, would you be able to try and answer the following question.
I am using the mySolr python library but there are others out (like pysolr) there and I don't think the problem is related to the library itself.
I have a default multicore SOLR setup, so no authentication required normally. Don't need it to access the admin page at http://localhost:8080/solr/testcore/admin/ either
from mysolr import Solr
solr = Solr('http://localhost:8080/solr/testcore/')
response = solr.search(q='*:*')
print("response")
print(response)
This code used to work but now I get a 401 reply from SOLR ... just like that, no changes have been made to the python virtual env containing mysolr or the SOLR setup. Still...something must have changed somewhere but I'm out of clues.
What could be the causes of a SOLR 401 reponse?
Additional info: This script and mor advanced script do work on another PC, just not on the one I am working on. Also, adding "/select?q=:" behind the url in the browser does return the correct results. So the SOLR is setup correctly, it has probably something to do with my computer itself. Could windows settings (of any kind) have an impact on how SOLR responds to requests from python? The python env itself has been reinstalled several times to no avail.
Thanks in advance!
The problem was: proxy.
If this exact situation was ever to occur to someone and you are behind a proxy, check if your HTTP and HTTPS environmental variables are not set. If they are... this might cause the python session to try using the proxy while it shouldn't (connecting to localhost via proxy).
It didn't cause any trouble for months but out of the blue it did so whether you encounter this or not might be dependent on how your IT setup your proxy or made some other changes...somewhere.
thank you everyone!

Cannot connect to RabbitMQ on Heroku with pika due to ProbableAccessDeniedError

I just set up a RabbitMQ add-on in heroku. After developing my app to queue up and consume messages running on a local instance, I deployed it to Heroku and have not been able to connect successfully yet. The username/password & hostname/port/vhost are all from heroku config. If I change the username or password, the error changes to ProbableAuthenticationError which makes me believe the authentication is at least correct, but likely an issue with my vhost or some other missing configuration. I haven't seen any similar questions on SO or after an hour of Googling that didn't address my issue.
I have tried both the RABBITMQ_BIGWIG_RX_URL and RABBITMQ_BIGWIG_TX_URL environment variables for both sending and consuming, and no combination seems to work. Below is the code I have for attempting to connect.
url = 'small-laurel-24.bigwig.lshift.net'
port = 10019
vhost = '/notmyrealvhost'
credentials = pika.PlainCredentials('username', 'password')
parameters = pika.ConnectionParameters(url, port, vhost, credentials=credentials)
connection = pika.BlockingConnection(parameters)
Is there something I'm missing or any way to figure out what specifically is configured wrong? I'm at a loss here. Much thanks in advance!
I am running pika 0.9.14, python 2.7.3.
The problem was most likely that you added the forward slash character in your virtual-host. Many users confuse this with the forward slash being the root directory, but it is actually just the default virtual-host name.
Unless you actually named the virtual-host using a forward slash, the name will always be identical to the name you see in the management console, e.g:
my_virtualhost and not /my_virtualhost
This is why your solution worked as you did not add the extra forward slash when using URLParameters.
Your original code would have looked like this using URLParameters:
amqp://username:password#small-laurel-24.bigwig.lshift.net:10018/%2Fnotmyrealvhost
While the working version you mentioned in your answer above does not have the forward slash (%2F) character.
amqp://username:password#small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost
I ended up solving my problem by using the URLParameters class on pika to parse the URL from Heroku's environment variable.
This takes the string like
amqp://username:password#small-laurel-24.bigwig.lshift.net:10018/notmyrealvhost and parses everything as needed. I was unnecessarily complicating things by doing it myself.

Categories

Resources