AstronomyAPI / Samples

Examples for Astronomy API
https://astronomyapi.com
MIT License
30 stars 3 forks source link

Another 'equal-sign' warning struggle #57

Closed trebor89 closed 1 year ago

trebor89 commented 1 year ago

Hi;

Very sorry to bother you, I was hoping to onboard without issues but I'm struggling. I'm an experienced programmer in python and other languages but keep getting the 403 "missing equal-sign" message similar to previous issue requests.

I am using the requests api. I have tried manually constructing the Basic Auth header (which I have done many times before in other languages and settings) and also used requests' auth = (app_id, app_secret) tuple argument. I have tried re-creating my application in the console as well. Can you please help me determine what's wrong?

Below is my code, less the app_id and app_secret, which I copied from the console.

I'm very interested in using this API!

Thanks, --Trebor

import requests
import base64

app_id = "not"
app_secret = "anyone's business"

payload = {
    "style": "navy",
    "observer": {
        "latitude": 33.775867,
        "longitude": -84.39733,
        "date": "2019-12-20"
    },
    "view": {
        "type": "constellation",
    }
}

encoded = base64.b64encode(f"{app_id}:{app_secret}".encode("ascii"))

headers = {
    "Origin": "https://treborshankle.com",
    "Authorization": f"Basic {encoded.decode('ascii')}"
}

r = requests.get("https://api.astronomyapi.com/api/v2/studio/star-chart", headers = headers, data = payload)
print(r.status_code)
print(r.text)
trebor89 commented 1 year ago

Also if you have any details on the projection you use to generate these charts that would be greatly appreciated. I am looking to "back-project" the chart onto a sphere so that an illumination in the center will correctly draw the view as seen from the given location on walls.

I assume these projections are azimuthal, right? As in this?

astroanu commented 1 year ago

Hi;

Very sorry to bother you, I was hoping to onboard without issues but I'm struggling. I'm an experienced programmer in python and other languages but keep getting the 403 "missing equal-sign" message similar to previous issue requests.

I am using the requests api. I have tried manually constructing the Basic Auth header (which I have done many times before in other languages and settings) and also used requests' auth = (app_id, app_secret) tuple argument. I have tried re-creating my application in the console as well. Can you please help me determine what's wrong?

Below is my code, less the app_id and app_secret, which I copied from the console.

I'm very interested in using this API!

Thanks, --Trebor

import requests
import base64

app_id = "not"
app_secret = "anyone's business"

payload = {
    "style": "navy",
    "observer": {
        "latitude": 33.775867,
        "longitude": -84.39733,
        "date": "2019-12-20"
    },
    "view": {
        "type": "constellation",
    }
}

encoded = base64.b64encode(f"{app_id}:{app_secret}".encode("ascii"))

headers = {
    "Origin": "https://treborshankle.com",
    "Authorization": f"Basic {encoded.decode('ascii')}"
}

r = requests.get("https://api.astronomyapi.com/api/v2/studio/star-chart", headers = headers, data = payload)
print(r.status_code)
print(r.text)

Hi, if you have trouble encoding the username and password with base64, i would suggest encoding it using some other tool such as https://www.base64encode.org/ then using that string in the header. This encoded string will never change in your requests and it's perfectly fine to use it that way.

astroanu commented 1 year ago

Also if you have any details on the projection you use to generate these charts that would be greatly appreciated. I am looking to "back-project" the chart onto a sphere so that an illumination in the center will correctly draw the view as seen from the given location on walls.

I assume these projections are azimuthal, right? As in this?

The projection used is "mercator" and the library we use is here

trebor89 commented 1 year ago

Thanks for your response @astroanu . Unfortunately, neither base64encode.org nor echo -n "mystring" | base64 worked.

I think I found a more appropriate tool, I'm going to close my issue. Do you have something like a patreon or another way of receiving donations? This is a worthy project and I'd like to send some cash your way for putting up with me. I may end up coming back to this if I can't get my other solution working.

Thanks, --Trebor

astroanu commented 5 months ago

Hi, @trebor89 i have opened a gofundme. You can donate here https://gofund.me/15dfd06b