#web-development

2 messages · Page 12 of 1

neat nest
#

no yeah that's what you'd do

#

I was thinking about Flask sessions but your thing is AJAX based

sour heath
#

oh my

#

this seems extremely difficult to me

neat nest
#

I might be proposing something a little above what you feel ready for. it doesn't feel super complex to me, but I've sorta got the benefit of 5/6 years of passively absorbed web application design info

sour heath
#

I've got all of about a month

neat nest
#

these are all just recommendations that I think would make your ultimate objectives done to pass, but you don't need to take them if they sound too ambitious

#

as it stands your design sounds functional, just not as secure as you would like

sour heath
#

I mean, it sort of makes sense. I just feel like I would have to have the whole, two player complication figured out, that seems difficult as is

#

like, two people connecting together in a game

#

anyways, thanks

neat nest
#

I hope some of what I said helps a little, when others are available later I'm sure they'll have additional recommendations

junior hornet
#

Hi !

On my off-hours I've been trying to wrap my head around web dev + python.

Can anyone here explain how Flask and React/Vue would interact in a simple app?

wary mantle
#

I want to create a website for my discord bot. I want users to be able to login with their discord account and I want to grab their id and servers they are in. How can I do this?

queen needle
#

Oauth2 and the discord API is what you're looking for @wary mantle

wary mantle
#

Oke..

ivory crest
#

I'm using python social auth's steam openid with flask-login to handle authentication/logging in and saving to mariadb with sqlalchemy. I have several different projrcts all using the same setup and I'd like to unify them by using one database for users data.

The user database would contain the following tables linked with foreign keys to the user table: user, roles, profile core, profile project1, profile project2, etc.

This way a user can login on whichever site the same way as before but the sqlalchemy user model would have a different binding and database so they can share information.

So my question is what's the best way to handle the user model? I was thinking have a separate models.py to maintain with the users / roles table. Should I include the profile/site specific tables in this external file as well for simplicity?

native tide
#

anyone familiar with postgres?

tame viper
#

if it's a question specifically about postgres, it may be better to ask in #databases. other than that, don't ask to ask, just ask :)

gritty locust
#

Hello guys, I'm running into a problem on my socket application:

My server receives data from admins, and then broadcast it to all clients connected.

The problem is, It looks like it is "storing" the past data, for example:
Server-> THIS IS A HUUUUGE MESSAGE
Client has received-> THIS IS A HUUUUGE MESSAGE

Server-> tiny msg
Client has received -> THIS IS A HUUUGE MESSAGE tiny msg

Is anyone familiar with it?

#

Sorry, it receives: tiny msg THIS IS A HUUGE MESSAGE

sour heath
#

How exactly do people create a new 'session' for each person visiting a site

#

to prevent the mixing of variables

polar wasp
#

@gritty locust would need to see your code

#

@sour heath probably with a framework that does it for them, but what you'd do is give each client a unique id (e.g. in a cookie, or appended as a URL parameter) and use that as a key to something like a dictionary containing session data

sour heath
#

this 'session' would contain a few classes data

#

would that work?

polar wasp
#

whatever you want to put in it

sour heath
#

cool

#

would you describe it as difficult?

polar wasp
#

idk

sour heath
#

hm

sour heath
#

I could use sql to store such data

#

or does that not make sense?

polar wasp
#

you could

#

you'd need to do that if you have multiple server processes, certainly

sour heath
#

multiple server processes?

#

assuming I get all this storing of data and such working, how am I supposed to know when the person has logged off?

polar wasp
#

well

#

if they log off directly, there will be a log off page

#

otherwise just have an expiration date, maybe pushing it back whenever they have continued activity @sour heath

#

at that point, you purge the session data when they log off (make sure you can't ever reuse the key), or periodically purge all expired ones.

sour heath
#

Well, not exactly a login sort of thing, I meant when they exit the page

#

I'm also not sure how to prevent the same person from being in the db several times

polar wasp
#

well, you can't. just have an expiration

#

also, it's not necessarily bad to have the same person in the db several times

#

sessions aren't users

sour heath
#

I could also store that data somewhere to process it, cool

#

Well, the session key would be randomly generated

#

I get what u mean

#

Just will have to do some fancy stuff with sql

inner dagger
#

Do any of you use Pyramid?

native tide
#
if form.validate_on_submit():
    flash(f'Account created for {form.username.data}!')```
what does that code mean
it is in flask
strange thorn
#

look at the top of the file, flash should be imported there somewhere, that or there is an import * check the docs of that module for the flash function and you will know

#

@native tide

native tide
#

checked

#

and now i know what it does

#

@strange thorn thanks nix

strange thorn
#

np

gritty locust
#

@polar wasp Thanks, I "fixed it" just sending spare data after the right one, for some unknown reason it works.

slate wave
#

hey guys

#

does flask have a post voting method or feature I can use?

#

I'm looking for a vote ranking system similar to whats used on reddit or imgur

strange thorn
#

you are thinking a lot too high level of flask

#

its a microframework, its built so you can build frameworks and stuff on top of it

#

what you are expecting is far too specific

slate wave
#

oh... well do you know of any plugin or something I could use for that?

#

I'm learning flask at the moment, so I'm just trying to get a handle of whats possible

strange thorn
#

nope, i guess you could google for one but it shouldnt be too hard

#

youll have to build an endpoint for voting

#

and that somehow inserts stuff into a db

slate wave
#

well, I found a reddit clone using flask, so I guess I can scavenge the feature from that later on

#

by the way, how much would it cost to hire a developer to make a site with basic similar features as imgur?

#

so, text/img downloads, content management system, user logins, etc

native tide
#

is it possible to make render_template change the url?

#

i can't use redirect bc I want to pass in variables

#
@app.route("/search", methods=["POST"])
def search():
    searchobj= request.form.get("searchobj")
    query=request.form.get("query")
    query="%"+query+"%"
    if searchobj == "title":
        result= db.execute("SELECT * FROM books WHERE LOWER(title) LIKE :query", {"query":query}).fetchall()
    elif searchobj == "isbn":
        result= db.execute("SELECT * FROM books WHERE LOWER(isbn) LIKE :query", {"query":query}).fetchall()
    elif searchobj == "author":
        result= db.execute("SELECT * FROM books WHERE LOWER(author) LIKE :query", {"query":query}).fetchall()

    return render_template("results.html", result=result,query=query)
verbal flame
#

When im adding an h1 tag, it adds a margin?

native tide
#

@native tide you could probably make it change the URL using a HTML redirect on the page, if that works
otherwise no

#

not without JS

native tide
#

does anybody know of any good free web hosts?
i'm looking for something with ssh

heavy holly
#

any good resources for learning flask? I have been using python primarily for data analysis (hello Pandas :)). I have realized that data models tend to pushed as a web service in most projects. From what I have read, it's either Flask/Django. I have decided to start with Flask given how it breaks everything down. The closest to any knowledge of web dev is basic html

keen ore
#

im getting A required parameter "client_secret" is missing when trying to login using linkedin with authlib

prisma marsh
#

from the same author there's also a book, "Flask web development", edited by O'Reilly

#

I really liked them both

heavy holly
#

@prisma marsh I will check it out. What do you think of TeamTreeHouse as a learning platform as well?

prisma marsh
#

can't really say, I don't have any experience with that, sorry

heavy holly
#

no problem

keen ore
#

can someone here help me with authlib?

keen ore
#

how can i get the profilke details after user authenticxates with the oauth?

#

i want to get the profile picture and email of user after they link their linkedin accounts

#

im using authlib

keen ore
#

anyone? im really stuck
i tried

resp = oauth.linkedin.get('people/~?format=json')

but that just gives me

KeyError: 'token_type'
gritty locust
#

Hello guys, does anyone here have some experience with socket / client-server application programming ?
Looks like my client scripts are "going down" after x random minutes and are unable to reconnect.

strange thorn
#

!t g ask

lavish prismBOT
#
ask

Asking good questions will yield a much higher chance of a quick response:

• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.

You can find a much more detailed explanation on our website.

gritty locust
#

My clients script are going down after x random minutes, and are being unable to properly reconnect to the server.

The clients recv() data all time, the server always ping from 1 second to 1 second, the only time that I could see/log the exception it looks like it throws an error on recv but the server was not shutdown for even a second.
What could cause this type of problem?

strange thorn
#

i will not be able to magically tell you whats happening if you dont show me the code, as stated in point 3

gritty locust
#

@strange thorn It is too big to paste on discord so you can access here:

#

Password is 123.

strange thorn
#

ah

gritty locust
#

Password: 123
Tell me if you're unable to access it.

strange thorn
#

i can see the code

#

but eh

#

the client script isnt really doing anything?

#

its just a function definition

#

nothing else

#

nothing gets executed etc

gritty locust
#

It runs on thread, the While loop is always on recv(), based on decoded data you can see that sometimes it calls a function ( for example: ProcessarOrdem(str_recv) )

#

The problem is: After some random time, recv() breaks (lose connection to server?), BUT even if it breaks, it re-define the socket on the exception and reconnects (when it is working fine), but looks like some time It cannot reconnect to server, even it being online and running fine.

strange thorn
#

how many threads of the client are you running?

gritty locust
#

It is initiated just one time.

strange thorn
#

so that isnt the problem

#

hm

#

the reason for you not getting error messages is very likely that you are skipping most of the errors in the server script

#

you should print them at least

#

do that and try again if you see error msgs

gritty locust
#

I've tried that, but it just standard erros like WinError 10054 or 10056 , connection closed or something like that.

strange thorn
#

comment the try excepts out so we get a traceback to the line where it happens then

gritty locust
#

There is a way to log it without the Try and Except? Because as I said, this happens randomly , it is being really trick to get the exception as there is times that this takes hours to occur.

#

There is a way to log it without the Try and Except? Because as I said, this happens randomly , it is being really trick to get the exception as there is times that this takes hours to occur.

strange thorn
#

there is the so called traceback module which allows you to generate a traceback like you would get it if you let the try excepts out

#

but logging errors without try except and without crashing is impossible

gritty locust
#

Ok, I will try that, thank you.

native tide
verbal flame
#

When im adding a div, the background does not go all the way down

native tide
#

anyone know how to use the same variable in a different flask route?

simple knoll
#

So I’m making a website using Django that I’ll be hosting in DigitalOcean. I’ve been reading about using an Amazon S3 bucket to serve static files for it. I understand that in theory it’s supposed to speed up load times. My question is, at what point should I start caring about those load times for a few files? The other websites I have created seem to load quickly even with all the (few)static files hosted locally so is it something I shouldn’t concern myself about with small scale projects?

small knoll
#

@heavy holly hope you don't mind me asking, what resources are you using to learn data analysis?

heavy holly
#

@small knoll mostly Pandas/Numpy/Seaborn/Statsmodel

buoyant ledge
#

i did

strange thorn
#

It was working properly for me

lucid marsh
#

I'm having problems with handlnig circular imports in Django ..
As an alternative to regular imports, I'm currently fiddling around with get_model
this throws the models aren't loaded yet exception though
Is there any way to work around this?

cerulean thorn
#

I need help working with the flask restful API and Postgresql

#

$$ Plus lucky charm included

keen plume
#

🙄

cerulean thorn
#

Hey @keen plume

brave mantle
#

We don't offer paid support here (for a myriad of reasons)

#

!t ask

lavish prismBOT
#
ask

Asking good questions will yield a much higher chance of a quick response:

• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.

You can find a much more detailed explanation on our website.

cerulean thorn
#

Sure

keen plume
#

That doesn't mean PM me

cerulean thorn
#

Sorry

#

I thought you were interested

keen plume
#

You haven't asked a question, how would we know if we're interested?

cerulean thorn
#

Okay, i'll do

formal condor
#

I am working on a closed corporate network and I am not exactly sure about the http authentication method to use for requests, to login and scrape from data from this web resource. I am trying to use the requests module with python 3.6.5. every time I try to push my authentication I get a response off the session as 200 but I am not able to get the page I want, it remains the login page every time. I think this is because whenever I login to the web resource in a browser, once I enter my credentials, I get hit with an alert asking me to agree with terms of service. How can I format that in my post request?

#

Is there something I am doing wrong?

#
import requests 
from bs4 import BeautifulSoup 


with requests.session() as mySession:
    url = 'https://login.mycompany.com/onesso/login.jsp'  # Url where I login to authenticate myself
    url2 = 'https://aboutyou.mycompany.com/'              # Url where I go to scrape data
        
    myHeaders = {'User-Agent': 'Mozilla/5.0 (Macintosh;'
                           ' Intel Mac OS X 10_10_1) '
                           'AppleWebKit/537.36 '
                           '(KHTML, like Gecko) '
                           'Chrome/39.0.2171.95 Safari/537.36'}
    
    myReq = mySession.post(url, auth= requests.auth.HTTPDigestAuth('USERNAME HERE', 'PASSWORD HERE'),
                                                                    allow_redirects=True, 
                                                                    headers=myHeaders)
    newReq = mySession.get(url2, 
                           allow_redirects=True, 
                           headers=myHeaders)
    print (myReq.text)
    print ("------------\n")
    print (newReq.text)```
wanton raptor
deep cave
#

@stable summit Flasks "advantage" over Django are that you can approach the problem in a more bottom-up way rather than top-down. it comes with almost nothing, so you put in what you need. if you're building a smaller app, this is fantastic. if you're building a massive superapp, it might mean you have to do a whole lot of groundwork before you can start actually making the app.

#

django is great, too, if you're building something that needs all of the features it comes with right out of the box. if not, it might be overkill.

#

I don't really see them as competing frameworks.

#

they're just two tools for different jobs.

#

flask is much better for beginners, though, since you don't have to learn what ORMs, classes, data models, relational databases, migrations and so on are in order to write a simple app.

languid bison
#

I'm not sure if it's the right place to ask, but has any of you tried to automate the renew of a wildcard letsencrypt certificate with a python script ? The acme-python api that comes with certbot does not seem to be able to handle wildcards certificates at the moment

fossil patrol
#

If you're on Linux just dump it into a cronjob

#

Doing it with Python is not really efficient cuz Let's Encrypt provide an easy enough cli interface

quartz maple
meager anchor
#

@languid bison if you just want to automatically renew the certificates without any python, you can create a systemd timer or cronjob to do it. IIRC if you install certbot it's gonna automatically install a timer

#

@quartz maple do you have a question?

languid bison
#

@meager anchor actually for wildcards certificates it's a bit harder, you need to edit a TXT record in your DNS in order to get a signed certificate from LE

#

and certbot isn't able to do such thing

#

@fossil patrol same answer as above, if it was a standard certificate yes a cronjob would be the easy way, but it's a wildcard certificate 😃

meager anchor
#

oh I see, I haven't used wildcard certs from LE before

fossil patrol
#

Ah, I didn't read that it was wildcard

wicked mason
#

how would I assign canvas elements ids, so I can refer to them later in my javascript code?

#
canvas = document.getElementById("cvn");
ctx = canvas.getContext("2d");

var gradient = ctx.createLinearGradient(0, 0, 100, 0);

gradient.addColorStop(0, "#00FF00");  // add id "first"
gradient.addColorStop(0.5, "black");  // add id "second"```
#

so I can then do document.getElementById("first")

stable summit
#

@deep cave the learning curve to get up and running with flask for small crud apps seemed non existent when I made a small project with it, it made me implement users/login system from scratch which isn't really the case in django but it was satisfying xD

olive wharf
#

How much interaction can you get between any of the web libraries (Flask, django, etc..) and php?

deep cave
#

what do you mean by interaction between them

wanton raptor
deep cave
#

@olive wharf interaction?

olive wharf
#

No idea

#

Using php, with python etc

kind steppe
#

They are different softwares, you can request one from the other but there isn't much you can do to get them to work together

olive wharf
#

So theres no smart way of replacing tasks in php with python?

kind steppe
#

I guess you could call Python code from inside PHP by running it using exec or whatever to run a command

olive wharf
olive wharf
#

Now the real question is, why choose php over something like js or python

#

What does php offer that those dont

river sinew
#

what do you think about sanic for small projects?

#

Did you have any experiences with it? If yes, tell me about them!

mental chasm
#

@olive wharf You wouldnt

neat nest
#

PHP offers an incredibly large web dev ecosystem with very speedy solutions. I don't like the language any more than y'all do but let's not pretend it doesn't have legitimate uses

mental chasm
#

it doesnt anymore

neat nest
#

that's a silly thing to say

kind token
#

Php has so much documentation and has been around for so long that it won't be going anywhere anytime soon

quartz maple
#

@meager anchor no.

quartz maple
#
from site import app

if __name__ == "__main__":
    app.run()
``` this is my code. I am trying to get Gunicorn to propagate.

This is the error I am recieving: https://paste.pythondiscord.com/oqezomitic.py
#

Can anyone help with this receeding error?

quartz maple
#

I got it working.

#

But ,

#

● myproject.service - Gunicorn instance to serve myproject
   Loaded: loaded (/etc/systemd/system/myproject.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-08-08 10:00:55 UTC; 6s ago
  Process: 1565 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited,
 Main PID: 1565 (code=exited, status=217/USER)

Aug 08 10:00:55 KCWS systemd[1]: Started Gunicorn instance to serve myproject.
Aug 08 10:00:55 KCWS systemd[1565]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such p
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Main process exited, code=exited, status=217/USER
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Unit entered failed state.
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Failed with result 'exit-code'.
#

could be the possible cause

tame viper
#

that sounds like a permissions problem, which i believe was identified half a century ago at this point.

quartz maple
#

No it's not.

#

it's a misconfigured nginx file.

tame viper
#

so then what's the nginx file?

meager anchor
#

if you have your nginx vhost set up properly then you get a gateway error

#

502 bad gateway

#

403 sounds like your vhost is not set up properly

quartz maple
#

server {
listen 80;
server_name server_domain_or_IP;

location / {
    include proxy_params;
    proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
}

}

it WAS that

#

server {
listen 80;
mydomainname.ca;

location / {
    include proxy_params;
    proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
}

}

#

Now its that

meager anchor
#

mydomainname.ca;

#

thats not how nginx directives work

#

server_name mydomainname.ca;

quartz maple
#

im not gonna tell you my domain name am i?

meager anchor
#

that wasn't even what i was pointing out

quartz maple
#

it's obviously my actual domain

meager anchor
#

but if you don't want help, then alright 👍

quartz maple
#

I also have another one (thats old)

#

caled main

#

Does it need the ; at the end?

#

@meager anchor

#

got it,

#
Aug 08 10:16:01 KCWS systemd[1720]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such process
#

It's still saying that.

#

I don't see that as a permissions error, because of the fact that everything should be working JUST fine

tame viper
#

volcyy was telling you to put server_name before your domain

quartz maple
#
Process: 1720 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited, status=217/USER)
 Main PID: 1720 (code=exited, status=217/USER)
#

I did...

#

server {
listen 80;
server_name domain.ca;

location / {
    include proxy_params;
    proxy_pass http://unix:/home/inteca-webmaster/myproject/myproject.sock;
}

}

#
Process: 1720 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited, status=217/USER)

Inteca-Webmaster should have all perms to that directory as it owns that directory

#

But maybe it can't be accessed via web?

#

I'll fix it myself.

#

I have indeed done that.

#

I'm getting 502.

#

Getting error 502 now.

#

Can anyone help me?

meager anchor
#

gunicorn isn't running, so the proxy pass isn't working properly

#

502 means The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.

quartz maple
#

Well the proxy pass is correct.

meager anchor
#

yes, but gunicorn isn't running

quartz maple
#

Should be, @meager anchor based on .service.

meager anchor
#
Aug 08 10:16:01 KCWS systemd[1720]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such process
#

# systemctl status gunicorn

#

if it says "failed", "stopped", anything like that, it isn't

quartz maple
#

Well how do I fix that

#

Afk

quartz maple
#

I’m back

#

However, note I’m on my iPad.

#

@meager anchor sir can you help me fix my problem?

meager anchor
#

you can probably not do much about it from your ipad

#

check what systemctl status is saying about gunicorn

native tide
#

Hey guys, how would I limit uploads on my server to like 5 uploads a minute

mental chasm
#

Do you require them to login?

#

@native tide

native tide
#

no

mental chasm
#

Then you would have to limit it by IP I guess

native tide
#

is there anything already done like this?
or would I have to find IP add a session timer

mental chasm
#

Most likely yes

native tide
#

thanks

meager anchor
#

@native tide you can use nginx's built-in ratelimiting if you want

#

and if applicable

native tide
#

ah my bad it's a python flask server

meager anchor
#

it's set up behind a reverse proxy though isn't it?

native tide
#

and I'm kinda low on ram

#

I have 1gb, back end is implemented in C to save memory

#

since I'm a hobo and don't want to pay

#

😄

#

@meager anchor I can use flask's ratelimiter tho

meager anchor
#

can do that. but nginx can also do it, and nginx receives the requests in the first place 😛

native tide
#

how much memory would nginx consume?

meager anchor
#

nginx is very, very, efficient

#

one second

#

also 1 GB is tons

native tide
#

I forgot to say I'm already using 600mb ram for processing

meager anchor
#

i forgot how to read memory usage of a process 🙃

native tide
#

I'm on windows server 2016

meager anchor
#

nginx probably - oh

native tide
#

can nginx return http status codes?

#

say if I run nginx and I have like 10 users a second max

#

how much memory do you thin it would consume?

meager anchor
#

10 users a second is near nothing

#

nginx is a web server, surely it can

native tide
#

if it's like 5mb of ram for 10 users a second

#

I'm set

#

nginx it is

mental chasm
#

You're running windows on 1gb?

meager anchor
native tide
#

@mental chasm yes

#

deseprate times call for desperate solutions

mental chasm
#

That's brave

native tide
#

15% CPU and 1MB of memory to serve 11,500 requests per second. lmao I'm set

#

no problems

#

gonna have to turn of windows server 2016 gui

#

and turn off that anti-malware executable since it's a fucking ram eater, because I run all my shit in a sandbox

#

and yes a sandbox in a 1gb ram machine

real phoenix
#

does anyone know how i can deply a python app on a plesk vhost? using nginx+apache?

#

*deploy

native tide
#

@meager anchor I was looking at how I could implement everything

User attempts record -> nginx checks if uploads -> flask would have to check if the upload is legal -> increase nginx user ip related upload amounts -> return a custom error code that includes seconds that the user has to wait -> parse error code in JS?

meager anchor
#

I'm not sure if nginx can cache by upload body, check out what I linked earlier, you might be able to use that as a cache key

native tide
#

the why use nginx?

#

ah rate limiting

#

ok so I'm still a bit confused on how to limit user uploads to like 20 uploads/hour

#

ok I'm just gonna do this I'm gonna ratelimit a user to 2 uploads per minute , if they upload the incorrect stuff ¯_(ツ)_/¯

native tide
#

welp turns out I ended up doing it in python

#

so I'm checking how flask responds to files above the max size, so my browser sends an xhr request, then flask returns a 413 but my browser doesn't see the error code in the network

quartz maple
#

It’d say systemctl status gunicorn?

native tide
#

@quartz maple ?

native tide
#

someone please bless me with an answer

native tide
#

on the right hand side is xhr post request succeeded, on the left hand side is flask declining a xhr post

#

JS can't understand that it's a 413

#

TCP packet by the way

native tide
#

Welp turns out it's a giant issue at the httplib level so im fucked

quartz maple
#

Yeah its very hard to get an answer here.

#
Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 583, i                                                                                                             n spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                             29, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1                                                                                                             38, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, i                                                                                                             n wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52                                                                                                             , in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41                                                                                                             , in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in i                                                                                                             mport_app
    __import__(module)
ImportError: No module named restart
[2018-08-09 06:04:35 +0000] [26957] [INFO] Worker exiting (pid: 26957)
[2018-08-09 06:04:35 +0000] [26953] [INFO] Shutting down: Master
[2018-08-09 06:04:35 +0000] [26953] [INFO] Reason: Worker failed to boot.

#

I restarted gunicorn,

#

as suggested

#

and i got that ^

#

I'm not sure if I restarted it correctly.

#

@neat nest ?

#

It looks so.

neat nest
#

you ask terrible questions from devices you can't use to debug, what answers are you expecting, exactly?

#

that doesn't look like you restarted anything properly, notice the ImportError

quartz maple
#

Yes...

#

I see that

#

How do I restart gunicorn?

neat nest
#

I'm pretty sure you were told NOT to restart it

#
you don't need to restart gunicorn, you can tell it to reload and it will gracefully stop and start new workers, IIRC```
#

as per Volcyy

#

oh that's directed at someone else

#

even so, I can't find any record of anyone here telling you to restart it

#

did you take Volcyy's most recent recommendation? it's got nothing to do with restarting the service

quartz maple
#

root@KCWS:~# systemctl status gunicorn
Unit gunicorn.service could not be found.

#

...

neat nest
#

.service looks familiar, can you think of anywhere else you've seen that?

quartz maple
#

I fixed it

#

Dw

#

I made a small, mistake.

#

Without noticing.

#

But thank you anyway @neat nest.

native tide
#

Fuuuuuuuuuuuuuuuuuck now Im going to have to tell my users that they shoule not upload a file bigger than 16mb imstead having an erroressage when they do

mental chasm
#

What happens if they do

native tide
#

My xhr doesn't get a response

#

But w/e problem is very low-level

#

Can't solve with python

quartz maple
#

Good news, @meager anchor I solved my issue.

#

I know you don’t care, but I just wanted to let you know.

prisma marsh
#

just a question before I dive in "two scoops of django". Is the book still actual? Are the info written for version 1.11 still (somewhat) valid for django 2.x?

buoyant ledge
#

Best book on Django / flask?

gaunt lava
#

real quick question about terminology - so discord and slack will display mini-previews for certain links pasted into chat, like YT vids or images. is 'unfurling' the correct word to use when describing this feature?

#

that is apparently what slack uses internally

#

i just can't tell if there's a more technical term for it

teal scroll
#

i need help with something

#

i made a text input box

#

and i want to do something like

#

if someone puts text in there

#

and leave

#

and come back

#

it should still be there

#

how would i go about doing that

knotty lark
#

@teal scroll You can do that completely client-side with JavaScript and local storage or cookies

teal scroll
#

hmm

#

@knotty lark ok thanks

buoyant ledge
#

@gaunt lava i think you're referring to embedding and its based on some graph tags, Open Graph maybe? i can't remember off the top of my head

winter hearth
#

I'm thinking of start working with web dev soon but don't know how and what to do.

#

What have y'all done and with what?

#

I know I wanna use Flask.

#

But the rest, I really dunno.

rigid turtle
#

All the web critters are about to wake up

#

So hold tight m8

junior hornet
#

@winter hearth

Here's my procedure data i've been collecting

#
  1. Full tech list explained

https://codeburst.io/want-to-build-a-cutting-edge-data-app-heres-the-tech-to-do-it-2576658eff96

• Backend Language: Python 3
• Web framework: Flask and Flask-Restful
• Database: Postgres + SQLAlchemy + FlaskMigrate
• Server: Nginx
• Frontend Framework: React.js
• Frontend Data Management: Redux
• Frontend Asynchronous Requests: Redux Sagas
• Styling: Styled Components
• User Authentication: Auth0
• Package Management: Webpack

codeburst

If you’ve ever tried to build an application that uses some cool data science/machine learning smarts, you’ll know that there’s a huge…

#

• Deployment: Multicontainer Docker to AWS with ECR and Elastic Beanstalk

  1. Full tech list explained 2 (python as well)

https://www.youtube.com/watch?v=s6NaOKD40rY

  1. 1 Going from an Idea to a Pitch: Hosting your Python Application using Flask and Amazon Web Services (AWS)

There has been a lot of noise about being a "full stack developer" recently. What does the full web stack look like for Python and how do you go about learni...

▶ Play video
#
  1. 1 Going from an Idea to a Pitch: Hosting your Python Application using Flask and Amazon Web Services (AWS)

http://amunategui.github.io/idea-to-pitch/ (text)
https://www.youtube.com/watch?v=3HuYr6G2Z28 (video)

Let's see how easy it is to transform an idea into a web application. This is for those who want to quickly pitch their application to the world without gett...

▶ Play video
#

In this video we will install and configure our Nginx web server and the MariaDB database server. See the whole lesson in the playlist “Deploying Flask Appli...

▶ Play video
Udemy

Learn to create scalable web applications that can serve millions of users using Flask, MongoDB and Amazon AWS

#
Vue.js Feed

Vue.js full-stack single page application served over Flask microframework & a tutorial on how it was built

SecDevOps

The full source code for this project can be found here and a live demo can be found here.

winter hearth
#

Ty

#

Thank you so much. I will begin to check all of this

winter hearth
#

Sooo

#

I'm gonna save all you sent because sadly most stuff didn't make any sense rn.

#

Like

#

It did make sense but I don't understand how I would use the info.

#

Gonna keep on watching everything though.

gaunt lava
#

@winter hearth have you ever done web dev before? maybe look into Django too

winter hearth
#

I havent thats the thing

gaunt lava
#

django might be a bit more approachable , its what I started with way back in the day

#

heck, its what I'm using right now

#

django REST framework for an API and im getting Vue set up for the front

brave mantle
#

Django tends to be very hard to approach for newcomers

#

It's huge and has a prescribed way of doing things

gaunt lava
#

how so? i mean i get that it comes with a lot of stuff

brave mantle
#

that's why we usually recommend flask

#

where you can get started in 5 lines of code

winter hearth
#

Yes I have seen some Django web development videos (tutorials) the thing is that it like. Was kinda weird I would say. I followed one and it like. Umm, I didn't do anything. Because all I did was change some true to false and reload the "website". Like then he started talking about different apps. It just felt like I was downloading someones discord bot and choosing the cogs I wanted to load but in a weird way.

gaunt lava
#

but the docs are really well written and actually learning the stuff makes web dev a breeze

#

but yeah, i learned django way back in '07

#

im willing to concede that things have changed since then

#

the official tutorial isn't bad

winter hearth
#

I can understand it's a very powerful framework. But I dont really feel like what I did was anything. It was like climbing a wall instead of a mountain. (Flask I guess) Like a wall is straight up so I have to smash all this info in my head until I'm at the top of the wall (learning curve, and know what to do) but with the mountain (I think lol) I can learn a small thing as I go through.

#

Let me try to the official tutorials then.

#

I'll be back when I've don't that. It's pretty late at night rn so maybe in one 11 hours (lol)

#

Ty guys

reef torrent
#

good evening! i've been working with python for a while now (super hack) for web based automation etc. Mainly Selenium. I use Docker to run most of my scripts, but i use a modified program for checking in with southwest airlines automatically. I am trying to make the commandline a webpage front-end. On that front-end it allows me to input the 3 command line items (confirmation,first,last) and then the script runs and sleeps until the time for checkin. During that sleep, I want the webpage to show the "sleeping" running python scripts..
any tips?
and also the ability to run new instances of the python script

mossy hamlet
#

Hello! Does anyone have any experience with Wordpress and Python? How can one incorporate Python in there etc.
E.g. using the Dash module to add neat interactive graphs on one's page

strange thorn
#

i dont have experience with it but wordpress is a PHP platform which is already pretty solid for itself you should maybe try to achieve stuff with PHP if you already have the platform @mossy hamlet

mossy hamlet
#

Hm, that'd probably take too much coding and learning, as Dash is a superb library and can create functional GUI with a few lines only. I do not know anything about php either.. The idea atm is to get interactive graphs up on the site.
I heard about some options on how to get Python scripts to WP. It seems to be very complicated still. But I was given some guidance and will look into <iframe> now.

orchid path
#

Hi pepol, so I was using vue for several of my projects and kinda wondering if it has a chance at become The One True Framework (haha classic) for view bindings over react. I really like it but on the other hand react is the big boys and big ecosystem and seem to be the prime candidate as a go to thing. So maybe I should submit to it too. 🤔 Any vue enthusiasts or webdev "zeitgeists" here to illuminate me?

brave mantle
#

I don't think Vue is going anywhere, but neither is React

charred turtle
#

Heyo, so I'm a bit on stuck on how to go about doing something. I have some items such as badges and buttons that are one colour and when I recieve some data I want them to change to a different colour, problem is that when I remove the class and add the new one there is a slight delay between the items changing colour, is there anyway to make it do it all at once?

#

Each object doesn't have the same class either.

grand badge
#

Your question isnt clear

#

!t ask

lavish prismBOT
#
ask

Asking good questions will yield a much higher chance of a quick response:

• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.

You can find a much more detailed explanation on our website.

charred turtle
#

I have 3 different items, a card header, a badge and a button, when the page loads they have classes "cardheader-black", "badge-black" and "btn-black" respectively, I want to be able to change the "black" part of each class to "purple", using removeClass and addClass doesn't do it at the same time so it's slightly noticeable, I'm asking is there a better way to go about doing this?

#

Hopefully that makes a bit more sense, sorry

grand badge
#

could you show the code you are working with please?

charred turtle
#
$('#CardHeader' + id).removeClass('cardheader-black').addClass('cardheader-purple');
$('#Badge' + id).removeClass('badge-black').addClass('badge-purple');
$('#Btn' + id).removeClass('btn-black').addClass('btn-purple');
#

That's how I'm currently doing it

#

But I'm sure there's a better way, just trying to figure out what

charred turtle
#

o, figured out a way

#

Thanks anyway!

native tide
#

I have a question about flask development, is there any way to use flask to change or add text to a text box? not manually but by python
I'm trying to make my chatbot web-based so I can use it on any device i wanted to any where
So I need to return data some how
Please tell me if there is a better way to do this

#

I have googled for quite a bit and I could only find the opposite, sending data from the text box to the server (post)

neat nest
#

you're going to need to write some JavaScript for the browser side that communicates back and forth with your Flask server

#

websockets are the latest and greatest way to do this kind of thing, there's also paradigms like AJAX that've been around for a while

native tide
#

alright

real phoenix
#

hm, i wonder, if i want to code a webinterface for my bot .... discord.py-rewrite ... would be flask or django better?

tame viper
#

probably flask, imo.

real phoenix
#

ok and how would i best code the interface. like, i wanna be able to access it remotely. now, should i run the app (integrated http server) or should i upload the webinterface somewhere? if iuploadedit it wouldnt run together with the bot and im not able to ... simply call methods etc. hm on the running bot

tame viper
#

do not run flask projects with the development server it comes with, that's for development and testing environments.

real phoenix
#

ok thanks a lot

#

😃

#

should i code with or without templates? oO

#

and is there anything like a default theme that looks good? or something because im usually not much into web development

tame viper
#

templates will be needed yes. as for a 'theme', i think you might want to look into a CSS framework to style your web page if you don't want to create the CSS yourself.

real phoenix
#

ok and how would i make the webinterface communicate with my bot? oO

tame viper
#

you'd probably have to have a coroutine running in your bot's event loop so that it can somehow listen/poll for incoming requests from the interface application.

real phoenix
#

hm ok thats much work for a simple thing like just displaying in which guilds the bot is in

tame viper
#

or maybe the bot can regularly write the statistics to a file which the site reads from in the same interval.

#

that's likely the easiest way. probably not the best way though.

real phoenix
#

hm maybe i shouldnt code a webinterface yet

#

btw, in pycharm how do i "create new project from git" without closing my current project?

tame viper
real phoenix
#

ok thanks 😃

native tide
#

Hey guys I'm ready for deployment, Ive got a domain, IP/DNS configured flask code optimized which production server do I use, I'm on windows server 2016

tame viper
#

windows server :^)

native tide
#

Yeah I had to

mental chasm
#

Why

native tide
#

Windows malware analysis

#

@tame viper are you telling me windows has a defualt server that I can configure with flask?

#

Holy shit that's some black magic

#

iis

tame viper
#

nah, i just automatically bash windows when i get the opportunity to. :D

mental chasm
#

What

native tide
#

@tame viper kinda had to use windows server though since malware analysis on windows

#

Rip

#

Would have used centOS/Debian

tame viper
#

yeah i get that, i'm half-joking :P

native tide
#

So what server should I use my python app with?

#

Flask app, any suggestions?

#

I'm thinking waitress

queen needle
#

a common setup for flask apps is nginx+uwsgi but I dunno if that runs on windows

native tide
#

Nginx is on windows so is uwsgi

mental chasm
#

Use them

mortal oar
#

i'm trying to scrape IP addresses from those 'free proxy list' sites, anyone advise me on some documentation or guides that will help me?

#

using python preferably.

brave mantle
#

requests-html is all you'll need

#

this is the wrong channel, btw

#

Use one of the general help channels

mortal oar
#

thanks

brave mantle
#

@near ridge For future reference ablobcatwink

near ridge
#

Mah bad

brave mantle
#

All good, man

signal karma
#

Hi, I have requests slow down on production with a Flask back-end, is that normal?

#

Some requests take a few seconds other take 15+ sec

#

randomly

#

Any idea why I'd get this behavior?

neat nest
#

that sounds like a problem specific to your situation and not a common bug

#

what are you using to serve it?

signal karma
#

gunicorn

neat nest
#

have you already checked gunicorn's logs for anything unusual?

wintry geyser
#

hey guys anyone here knows how to store a variable on the server side in javascript?

#

i found this var mJSVariable = <%:myServerSideVariable%>;

neat nest
#

that's very particular to ASP.NET, not quite as straightforward if you don't have a specialized framework for it

wintry geyser
#

i'm using flask

neat nest
#

standard fare is make an AJAX request to some route you define in your Flask application

wintry geyser
#

trying to get autofresh to work

neat nest
#

yup, AJAX is the way to do that

wintry geyser
#

is the problem so simple that I can't find anything on this

neat nest
#

you make your own HTTP request to a Flask route that doesn't provide a full page, but instead just provides enough information for you to update the page

wintry geyser
#

does it work across different pages?

#

cause I want to trigger an auto refresh on another page

#

not on the current page

neat nest
#

could you elaborate?

#

I'm not sure I understand your meaning

wintry geyser
#

like I press submit info

#

than the database would update, the admin would receive a signal somehow telling the browser to refresh

neat nest
#

I'm not sure something like that requires JS at all. that's just a regular form submission, isn't it?

wintry geyser
#

yep

#

I just need to trigger auto refresh somehow

#

as soon as the database change

buoyant ledge
#

You could just poll the database from the admin site every so often and check if it’s changed

wintry geyser
#

does that require php?

neat nest
#

but like... this doesn't require any polling, this is just a regular submission. am I completely off base in thinking the page ought to reload if the form action is the same route?

wintry geyser
#

uh.... different route

#

the end-user is just submitting something to the database, then returns to the 1 st page of request info (not the workspace)

#

the workspace route where the admin is, is separate

#

I think that's what u were referring to

#

so yes I think the http request thing is part of the answer, I just need to figure out some how.

wintry geyser
#

So i manage to send a http request but separating the function failed it. It can refresh the page where the code is place but not on a different html page.

#

workspace.html <script> function update() { if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.status === 200) { location.reload(true); } else { alert('There was a problem with the request.'); } } } </script>

#

request.html

  (function() {
    var httpRequest;
    document.getElementById("submit-info-button").addEventListener('click', makeRequest);

    function makeRequest() {
      httpRequest = new XMLHttpRequest();

      if (!httpRequest) {
        alert('Giving up :frowning: Cannot create an XMLHTTP instance');
        return false;
      }
      httpRequest.onreadystatechange = update;
      httpRequest.open('GET', 'workspace');
      httpRequest.send();
    }

  })();
</script>```
#

is there a reason why this doesn't work? I mean the httpRequest.open('GET','workspace') should connect the two functions right?

latent coyote
#

this is not very related to python, IM JUST WONDERING... are you allowed to sell a wordpress website?

sturdy sapphire
#

yes, as long as you follow the license

naive wing
#

Hi

#

Anyone good with flask here

neat nest
#

yes

#

so many people

#

sooooooo many people are good with flask in this place

naive wing
#

I am having trouble configuring two databases with flask and psycopg2.

#

I am not using any ORMs

#

I dont know how well I can phrase my question so that people can understand

neat nest
naive wing
#

It is a flask question because the database is working

neat nest
#

why two databases?

naive wing
#

I want to use one database for running tests and another one for storing data

#

because tests has teardown I dont want it to tamper with the actual data

neat nest
#

and what seems to be the issue that you're encountering?

naive wing
#

Its either my configurations or something I am missing.

#

As it stands, I can only use one database

#

When I try to configure, it only picks on db

neat nest
#

I mean, you should probably only be connecting to one at a time in any case

#

are you trying to connect to both at once?

naive wing
#

No

#

How do I connect it one at a time

#

I am trying this

#
    if 'test' in sys.argv:
            database = os.getenv('DATABASE_NAME')
        else:
            database = os.getenv('DATABASE_TEST')
#

@neat nest my problem is how do it tell the database connect that now, tests are running

neat nest
#

well... how do you normally connect?

naive wing
#

class DbConnection():
    """Initializes connection to the database and executes queries"""
    def __init__(self):
        # load credentials from environment
        if 'test' in sys.argv:
            database = os.getenv('DATABASE_NAME')
        else:
            database = os.getenv('DATABASE_TEST')

        # database = os.getenv('DATABASE_NAME')
        user = os.getenv('DATABASE_USER')
        password = os.getenv('DATABASE_PASSWORD')
        host = os.getenv('DATABASE_HOST')
        # uses credentials from the environment to connect to the database
        self.conn = psycopg2.connect(
            f"""dbname={database}
                user={user}
                password={password}
                host={host}""")
        # saves every database execution aumatically
        self.conn.autocommit = True
        self.cur = self.conn.cursor()

    # performs database queries
    def query(self, *args):
        self.cur.execute(*args)
#

@neat nest this is my db connection class

neat nest
#

looks like a nice piece of code. what's not working about it?

naive wing
#

When I run tests using pytest, I find the wrong database being populated

neat nest
#

you're running it with test in your argv somewhere?

naive wing
#

Lol. I dont know what that actually means just copied it from stack overflow..

neat nest
#

ah

naive wing
neat nest
#

understanding the code you write is usually essential to fixing it

naive wing
#

I understand that

#

But basically, i just need a way to tell the connector that know tests are running, please choose a different database name

neat nest
#

right. so what mechanism can you use to identify when tests are being run? because using the Django method probably won't work in your case

#

on account of you not testing with Django

naive wing
#

clearly

neat nest
#

really what ought to be happening, I think, is you pass a dbname to the class

#

instead of the class finding it itself

naive wing
#

There is one way using configurations

neat nest
#

oh?

naive wing
#

oh okay. db name to class

#

mnh..

#

I could try that

#

I was hoping to use the different working environment configurations to communicate to the db

#

but that is here I was stuck

neat nest
#

I mean, you can, this just doesn't seem like something the db init should be handling itself

#

discover the configuration outside of DbConnection and pass it in

#

also you should rename it DBConnection because it looks much nicer

naive wing
#

okay

#

can you write what you are thinking about?

neat nest
#
db_connection = DBConnection(host, user, password, name)```
#

or something to that effect

naive wing
#

And how that change what I have?

#

I mean how will it help me solve?

neat nest
#

it won't on its own, it just makes more sense to do it that way

you said "There is one way using configurations" but never elaborated. is there a way to tell when you're testing?

naive wing
#

Okay

#

I will examine your feedback. Thanks

#
import os


class Config():
    DEBUG = False
    TESTING = False
    SECRET = os.getenv('SECRET')


class Production(Config):
    DEBUG = False


class Development(Config):
    DEBUG = True


class Testing(Config):
    TESTING = True
    DEBUG = True


app_config = {
    'development': Development,
    'testing': Testing,
    'production': Production
}
#

This is my config file

#

That is where I am stuck

#

This is where I am loading testing configurations fr the app

meager anchor
#

use a different settings file per environment instead of class thing

#

then you can have a common file with shared settings and change what you need

#

e.g.

#
myproject/settings/common.py  # <- you star-import from here
myproject/settings/dev.py
myproject/settings/test.py
myproject/settings/prod.py
#

that's one way to accomplish it, I'm personally a big fan of django-environ

naive wing
#

Thanks

frigid hamlet
neat nest
#

I am afraid I do not understand it at all

brave mantle
#

yep, not gonna pretend that I have any idea what that's about

olive wharf
#

With a bit of context, maybe? Else I feel maybe sliders, and more spacing (if it's a phone display). I'd hate to misclick those tiny buttons

sour heath
#

Okay, I have a problem, I have my backend as python and my frontend as js and I have to do some stuff with jquery to edit the template which has to take place in the frontend. This is an issue as the only way to pass information from the front end to the backend is through jquery requests (that I know of). I have a card game and I have to replace images with more images but this requires making a flask url that passes the player hands which means its accessible to anyone, how could I fix such a thing. I've asked this before but I want to attempt to get a clearer understanding.

#

the data I need it for is for moving the cards from one section to another

#

I was considering just storing the player objects in the sql database I'm using for the sessions, but the player could simply use the debugger tool and track the vars that happen to be storing the data pulled from it

#

jquery has a move function but then I wouldn't know how to call a function in the python when a card is 'clicked' as that would require a url which means more chance of someone screwing with it

unreal dagger
#

I am having some trouble with nginx I have made a new conf file for deploying a django app and I can't seem to get nginx to point to my project. I can present my current config file or any other files if need be just let me know.

meager anchor
#

yeah

#

show us the configs hyperlemon

unreal dagger
#

One second

#

is the current config file

#

if you want to see the nginx.conf let me know

meager anchor
#

is django running?

#

also :8000 is the dev server

#

you should be using something like gunicorn

#

75 MB client max body size is also ... quite a lot, do you want people to OOM your server or something

unreal dagger
#

I plan on reducing it I wanted to stress test but I can't get the page to load anyway

#

and I can use gunicorn

#

I cant get nginx to proxy guni

#

and django is currently not running

shrewd sand
#

server {
  listen 443;
  listen [::]:443;

  root /var/www/sharpweb.me.uk;

  index index.html;

  server_name sharpweb.me.uk www.sharpweb.me.uk;

  location / {
    try_files $uri $uri/ =404;
  }
  ssl on;
  ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;
}
#

https://www.sharpweb.me.uk/upload.php

#

I am trying to get nginx to access my upload.php file

#

Which i use for sharex

#

But i get a 404 error

#

Anyone know whats going on?

unreal dagger
#

Dang

shrewd sand
#

@iron lark it shouldn be that hard

iron lark
#

it's never

shrewd sand
#

That link

iron lark
#

check your nginx logs

#

in /var/log

#

the file missing so maybe your rootfolder param is wrong

shrewd sand
#

The website loads

#

;/

meager anchor
#

@unreal dagger if django isn't running then nginx won't proxy anywhere

#

unless you have something else listening on 8000

shrewd sand
#

@iron lark invalid no of args

#

in root

iron lark
#
location / {
    try_files $uri $uri/ =404;
  }

Isn't it try_files $uri=404 ?

#

I might be wrong on this

#
location = /upload.php {

try_files $uri $uri=404

}
shrewd sand
#

try_files $uri $uri=404;

iron lark
#

try adding that

shrewd sand
#

I did that

#

ohhhh

#

That worked

#

Still invalid

iron lark
#

dunno then

shrewd sand
#

That's starnge

#

@iron lark im using cloudflare as my dns

#

Could that be a reason?

iron lark
#

nop

shrewd sand
#

ok

#
server {
  listen 443 http2 default_server;
  listen [::]:443 http2 default_server;

  root /var/www/sharpweb.me.uk;

  index index.html;

  server_name sharpweb.me.uk www.sharpweb.me.uk;

  location = /upload.php {
    try_files $uri $uri=404;
  }

  ssl on;
  ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;

  gzip on;
  gzip_types application/javascript image/* text/css;
  gunzip on;
}
#

My problem is getting upload.php to show for sharex

#

If anyone knows why i get a 404 error, lemme know ;D

unreal dagger
#

Resolved my issue

shrewd sand
#

@brave mantle root option stops any other file from not giving 404 except the index.html file?

brave mantle
#

Root sets the root of that server block

#

As in, where it looks for files

shrewd sand
#

Ok. So it's not that?

#

I just don't understand why my website loads fine, yet /I/ and upload.php give 404 errors

brave mantle
#

You don't even have PHP configured

#

You should have a location / block though

#

And you don't

shrewd sand
#

I did have that

#

Deleted it

brave mantle
#

The location block you already have should be that

#

Although your try_files is wrong too

#

It should be $uri $uri/ =404;

shrewd sand
#

Repz said to try not doing that

brave mantle
#

No, you should have that

shrewd sand
#

Wait

#

What is the location / block?

brave mantle
#

It applies to everything that doesn't have a more specific location block

shrewd sand
#

Ok so like a default setter?

#

What should it include?

brave mantle
#

The try_files

#

Are you listening?

shrewd sand
#

Yes

#

You are assuming I have base knowledge

#

I didn't put 2 and 2 together

#

Got it now sorry xd

brave mantle
#

Trust me, I've learned to not assume that :P

shrewd sand
#

Do you have tutorial handy?

#

You talked about setting up PHP... Something for that

brave mantle
#

No, I'm on mobile, having a date with a bowl of noodles

shrewd sand
#

@brave mantle why doesn't Nginx like Apache do this sorta thing by default ?

brave mantle
#

Apache doesn't do it by default either

shrewd sand
#

PHP worked for me straight away

brave mantle
#

Nginx does support PHP, but you do have to install php-fpm

#

Which is, honestly, a much better option than mod_php

shrewd sand
#

Ok

#

I'll remember that

#

Would /I/ be making a 404 error if it had a Apache access file?

#

Cause I don't understand why that would give a 404 otherwise

#

@brave mantle even if I didnt have support for PHP, it shouldn't give a 404 error should it?

brave mantle
#

It gives a 404 because you don't have an index file in there

#

And indexing is disabled

#

Afk, busy

shrewd sand
#

Smh why didn't I think of the word indexing in my searches

#

That should make finding the answer easier

#

Thanks a bunch gdude

shrewd sand
#

@brave mantle any idea why after installing php-fpm my website now shows this:

copper forge
#

because its working

#

i guess

shrewd sand
#

But i have a folder

#

With nginx confs

#

That was working earlier

copper forge
#

🤔

#

idk then

#

/r might have something

shrewd sand
#

I have been here for 2 hrs

#

Is showing the default page only

#

Any ideas?

brazen dune
#

Never used that before but maybe one of your config files is not pointing to the directory with your public web pages...

shrewd sand
#

Yeah just gonna have to check all of them 3 times over

#

It's super strange

brazen dune
#

Have you restarted your web (httpd, apache, etc) service since configuring it?

#

I always find when something is not quite right it's usually a simple issue. 😃

shrewd sand
#

@brazen dune if I typed in somthing wrong, Nginx should give you a error

brazen dune
#

🤷

unreal dagger
#

if there is something wrong with your config file you can use "nginx -t"

#

and it should tell you if there is something wrong with the conf file

shrewd sand
#

That's cool. Thanks

lucid meadow
#

um

#

is it possible for a 16 year old to make a website that everyone can see?

shrewd sand
#

Well I'm 16

#

And I had a website

#

So sure it is :D

#

Mine wasn't free. But in theory you could make a free one

lucid meadow
#

i think im too late to develop man everyone started developing good stuff at 12 i started basic python at 14 and still is on basic python

#

how was yours not free?

#

if you could homehost?

shrewd sand
#

Homehosting just ain't as secure

#

I only started coding in January and I'm doing really well so far

lucid meadow
#

i guess i aint just home learning im relying too much on education at offical places

little nexus
#

scaleway offers basic hosting for ~$3/month so it really doesnt cost much to make a public website and get your own server nowadays

brave kettle
#

scaleway super cheap

copper forge
#

we want free tiers forever

buoyant ledge
#

Azure offers a dedicated server free for. 12 months I believe

#

It’s not a high tier server but it’s something.

#

Aws has a similar offer. So that’s like 2 years of hosting there

rigid turtle
#

Yes

shrewd sand
#

My website now won't even connect

#

But if i use the default one, it does

#

I am using certbot to do my keys

#

How do i check that certbot is running, and that no other program is using my https port?

#
root@Sharp:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

#

Also, this isn't testing my files at all

native tide
#

hmmm turns out uWSGI isn't windows compatible

#

any ideas on how to serve my flask app?

shrewd sand
#

This returns a bad gateway

meager anchor
#

@shrewd sand nginx -t does test your files. it doesn't test whether they are doing what you want them to, it tests whether nginx can read and understand them, and whether that configuration would work or not

#

having a program figure out what you want to do with it is probably very hard if not impossible

#

show your nginx config

#

bad gateway means nginx tried to proxy but the upstream server didn't respond

shrewd sand
#

@meager anchor it didnt check anything in sitesenabled

#

Or did it?

#

Its now 404

#
server {
  listen 443 default_server;
  listen [::]:443 default_server;

  root /var/www/sharpweb.me.uk;

  index index.php index.html;

  server_name sharpweb.me.uk www.sharpweb.me.uk;

  location / {
    try_files $uri $uri/ =404;
  }

  ssl on;
  ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
      root /usr/share/nginx/html;
  }

  location ~ \.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
  }
}
#

Just trying to get sharex working

meager anchor
#

won't the first location block match first?

shrewd sand
#

According to the guide im fine

meager anchor
#

hmhmhmmm, but the guide doesn't have the try_files over there

shrewd sand
#

@meager anchor does it not?

#

Great

#

Any other ideas?

#

Just cause I can't test tonight

#

Just anything else you think could be wrong

meager anchor
#

ah, I was wrong, the php location block will take priority

#

the rest seems fine, haven't worked with fastcgi personally apart from fcgiwrap

shrewd sand
#

@meager anchor :(

#

The journey of failure continues

meager anchor
#

but you haven't tried anything new yet have you 🤔

shrewd sand
#

I have been working on this for 2 days

#

5 tutorials

#

40+ config changes

#

:$

buoyant ledge
#

@native tide serve it in windows using wsl

native tide
#

@buoyant ledge how is wsl for ram usage?

#

Im looking at waitress + nginz

buoyant ledge
#

I don’t have any issues out of it

#

8gigs of ram and it seems fine

shrewd sand
#

If I'm not mistaken he has 1

tame viper
#

where would be the best place to store user-uploaded files for a flask application?

meager anchor
#

as in, in the project itself or are you speaking about URLs?

tame viper
#

well, with my flask app people can upload files and they get a download link and whatnot, but where exactly should the files be stored on the server side?

meager anchor
#

the filesystem? Probably depends on your needs

tame viper
#

just somewhere out of the way of the app itself?

meager anchor
#

yeah

#

i store my static stuff in /var/www/website.com/...

#

could use e.g. /var/www/juanssite.com/media

native tide
#

@tame viper how are you using the files?

tame viper
#

think of it like a file sharing thing (it's similar to that, anyways)

native tide
#

I see then you can probably just save them in your filesystem

tame viper
#

yeah okay

native tide
#

@tame viper you should probably run them through a compression algorithm first though

tame viper
#

yeah i have

native tide
#

for filesharing that sounds kinda important

tame viper
#

yup

native tide
#

imo use django it’s so much easier to manage

tame viper
#

i'm actually having a great time working with flask here

#

quite fun ^-^

native tide
#

i like how django has a lot included

tame viper
#

it's just a matter of opinion, yeah :D

tame viper
#

holy fuck working with scss in pycharm pro is a damn dream

native tide
#

+1

proper hinge
#

does pycharm pro have the file watcher feature?

#

I use it in webstorm

strange thorn
#

File watcher?

proper hinge
#

yeah so it automatically makes the css file when it detects the scss changes

strange thorn
#

Uuuuh

#

Gdude should know that

proper hinge
#

well

strange thorn
#

I remember him talking about it

proper hinge
#

I could just check for myself 😄

strange thorn
#

But we have a script for that in the Gitlab repo so I'm not sure if it's actually a feature

proper hinge
#

pro only

tame viper
#

oh yup, i could have answered that. it's very useful.

brave mantle
#

Yeah it does, I use it

native tide
#

Hey guys, I'm a little lost here. So I'm trying to data bind JSON data from my Python file to my HTML file to determine a school's name, url, city, state, zip, and number of students. I'm trying to connect it to different HTML tags (ie. h2, span, etc), but I'm having trouble. If you're interested in helping me, I'd be eternally thankful as this project has incredible importance. For ease of reading, I'm copy/pasting what I wrote so far:

import requests
import json
import urllib2

api_key = "key_string_here"
url_base = "https://api.data.gov/ed/collegescorecard/v1/schools/"

# Makes a get request to collegescorecard API

r = requests.get("https://api.data.gov/ed/collegescorecard/v1/schools/?"
                 "school.operating=1&2015.academics.program_available."
                 "assoc_or_bachelors=true&2015.student.size__range=1..&school."
                 "degrees_awarded.predominant__range=1..3&school.degrees_"
                 "awarded.highest__range=2..4&id=240444&api_key="
                 "key_string_here")

school = r.json()
for item in school:
    url = ("https://api.data.gov/ed/collegescorecard/v1/schools?"
           "school.operating=1&2015.academics.program_available"
           ".assoc_or_bachelors=true&2015.student.size__range=1.."
           "&school.degrees_awarded.predominant__range=1..3"
           "&school.degrees_awarded.highest__range=2..4&id=240444&"
           "api_key="+api_key+"&fields=school.name,school.school_url,"
           "school.city,school.zip,school.state,2015.student.size")
req = urllib2.Request(url)
response = urllib2.urlopen(req)
response2 = response.read()
json_data = json.loads(response2)

params = {
    'api_key': api_key,
    'school.name': 'University of Wisconsin-Madison',
    'school.school_url': 'www.wisc.edu',
    'school.city': 'Madison',
    'school.state': 'WI',
    'school.zip': '53706-1380',
    '2015.student.size': '29579'
}

resp = requests.get(url=url_base, params=params)
data = resp.json()
native tide
#

hey guys does anyone have experience with the waitress server

#

I'm trying to serve my flask app

#

It gets hosted but I always get a URL not found

#

none of my routes are being found

#
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
app.config['MAX_CONTENT_LENGTH'] = 8 * 1024 * 1024
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

serve(app,0.0.0.0,8080)

@app.route('/hello')
def hello():
    return 'Hello, World'
meager anchor
#

is the 404 actually being returned by waitress? are you actually visiting the /hello route? which reverse proxy are you using, if any?

native tide
#

I am not using any reverse proxy, I don't know if the 404 is being returned by flask or waitress

#

I suspect flask

#

yes I have tried visiting the /hello url

#

still get a 404 which leads me to believe it's a waitress problem

#

@meager anchor sorry for the late response

meager anchor
#

so you have no other http server running on :80 or :443, that's all waitress. correct?

native tide
#

I'm testing on 8080

#

just to be sure

meager anchor
#

okay

native tide
#

and yes I have no other HTTP server running at port 8080

meager anchor
#

I have a feeling that the serve(app,0.0.0.0,8080) gets evaluated before the route gets added

native tide
#

are you telling me to server after all my defs

meager anchor
#

Can you try moving that to the bottom of the file?

#

Yeah

native tide
#

/route I will

#

@meager anchor thanks it seems to work

#

I feel very stupid right now

meager anchor
#

👍

native tide
#

hey volcyy if I've configured my DNS

#

and my domain I'd have to host with 0.0.0.0 to get my domain to start working

#

What are you using? flask or django

#

waitress serving a flask app

#

I've got my namecheap domain pointed to my AWS instance

#

I don't use flask, but is there like an allowed_hosts = [] anywhere?

#

yeah I'm on a production level server

#

now I'm having trouble getting my domain to connect

#

How long ago did you create the dns

#

5 days?

#

should be enough

#

ok, are you using an a record

#

an a record??

#

lemme tell you what's on my record set

#

What kind of record are you using

native tide
#

@native tide turns out it's not dns problems

#

my external IP is not actually connected to my internal IP

tame viper
#

👌

native tide
#

eh I wanna ask about AWS here

#

but it's not python

#

I fixed it just firewall rules

strong sonnet
#

Hey I don't suppose anyone here has knowledge of aiohttp?

#

I'm sending a JSON request to a service (an airconditioner) and sending the request through aiohttp doesn't seem to work. The request gets sent and a response comes in through wireshark but the aircon seems to just ignore the command.

#

I have tried sending it with the requests package, that works. The only real difference I can see between the two is that requests uses keep-alive while aiohttp doesn't.

#

I have tried using a TCPConnector to enforce keep-alive but that doesn't seem to work. Kinda out of ideas here....

deep cave
#

show us your code for sending the request?

strong sonnet
#

Looking at wireshark, there's a whole pile of odd TCP errors after the push, there's a TCP out of order packet sent by the server, then a whole pile of Dup ACK packets sent, and retransmissions sent back

#
    async def _send_command_async(self, command: str, data: Any, callback: Callable = None):
        try:
            body = json.dumps({command : data})
            async with self.session.post('http://%s/%s' % (self.device_ip, command),
                                         timeout=Controller.REQUEST_TIMEOUT,
                                         data=body) as response:
                await response.text()
                response.raise_for_status()
            if callback:
                callback()
        except (asyncio.TimeoutError, aiohttp.ClientConnectionError) as ex:
            self._failed_connection(ex)
#

(same thing happens without the timeout BTW, and I've tried removing the user agent and content type headers and it makes no difference)

deep cave
#

that looks like it won't be using the right headers

#

instead of using json.dumps() to jsonify that dict, just try attaching it directly to the post request with the json keyword arg?

strong sonnet
#

yeh tried that, no dice

#

Tried it with and without Content-Type

#

This is the sync version:

    def _send_command(self, command: str, data: Any, callback: Callable = None):
        # Do this synchonously. For some reason, this doesn't work with aiohttp
        body = {command : data}
        url = f"http://{self.device_ip}/{command}"
        try:
            with requests.post(url,
                               timeout=Controller.REQUEST_TIMEOUT,
                               data=json.dumps(body)) as response:
                response.raise_for_status()
        except requests.exceptions.RequestException as ex:
            self._failed_connection(ex)
            raise ex
#

These are the actual packets as captured by wireshark:

POST /SystemMODE HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Content-Length: 22
Content-Type: application/json
Host: 10.0.0.107
User-Agent: Python/3.6 aiohttp/3.3.2

{"SystemMODE": "auto"}


POST /SystemMODE HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 21
Host: 10.0.0.107
User-Agent: python-requests/2.19.1

{"SystemMODE": "dry"}
deep cave
#

huh.

strong sonnet
#

Have played around with content type and user agent, doesn't make any difference

deep cave
#

yeah your sync version wouldn't be sending that Content-Type json header either, it seems

#

and still it works

strong sonnet
#

The only difference is Connection: keep-alive

#

The response for both is code 200 = OK

deep cave
#

that's all you get in response?

strong sonnet
#

Yep, except for the whole pile of odd TCP packets which I don't really know how to interpret

deep cave
#

sounds like kind of a pain in the ass API to work with :P

strong sonnet
#

yeh it is 😦

#

But I'm writing a connector for home assistant so that will be good when done. Then I can automate my central heating better :p

#

heating / cooling

#

And more to the point, it gets me programming again which I've not been into for a while.

#

Is there any way to force aiohttp to use keep-alive?

deep cave
#

the way you already mentioned would be my approach.. though I suppose you could just manually set that header if you really wanted to make the requests look the same in terms of header data

strong sonnet
#

I was thinking of doing that. I might try that next

deep cave
#

doubt it will help, but worth a try

strong sonnet
#

shrug yeh. I suspect aiohttp will barf because you're putting the wrong header in

#

IDK if I can be bothered mucking about with it anymore, might just do it synchonously. Just seems a waste to be sitting there pointlessly using a thread waiting for IO

deep cave
#

I mean ultimately both of these libraries are probably using urllib to actually send the request. If you really wanna figure this out, you should probably whip out your debugger and walk through the requests, listen to some variables, and figure out exactly what's different.

strong sonnet
#

would they be however? I dunno... I could do some digging I guess. Maybe some kinda odd low level TCP issue or something.

#

It feels like the device itself is the problem, which clearly I've got little ability to fix

deep cave
#

yeah

#

but there's nothing about async in and of itself that would fuck with it

#

it's gotta be the request

strong sonnet
#

No! totally

#

I suspect the device manufacturers only ever used keep-alive, so it's untested otherwise

deep cave
#

and a request is a request. if it works sync, you can get it working async if you just figure out what's different and change it

strong sonnet
#

that's the only thing I can think of really

deep cave
#

but I am also stumped as to what that might be

strong sonnet
#

Maybe the device just doesn't like having TCP connections closed or something?

deep cave
#

you seem to be using aiohttp correct, fwiw.

strong sonnet
#

yeh that's what I think

#

async coding is kinda fun to get your head around

#

Back when I was doing this kind of low-level coding selectors had only just been invented, Java had only just brought it out

deep cave
#

good thing to get into.

#

home automation is fun. I just bought a house, I'm gonna be doing some more of that myself soon

strong sonnet
#

We used to just use thread pools

#

yeh 😄 get into home assistant, it's a lot of fun

#

I tell my google home "OK I'm going out" and all the lights turn off and the garage door opens

deep cave
#

super fun

strong sonnet
#

and the TVs and Radios turn off

#

it's like living in the Jetsons :p

#

Anyhow, gonna head home, ttfn

shrewd sand
#
server {
  server_name  search.sharpweb.me.uk;
  location / {
    return 301 https://google.com/;
  }
}

#

Why does this redirect not work?

#

I have my website server bracket underneath

brave mantle
#

You have no listen directive

shrewd sand
#

If i have multiple listens, does that not create a conflict?

brave mantle
#

No

shrewd sand
#
server {
  listen 443 default_server;
  listen [::]:443 default_server;

  server_name search.sharpweb.me.uk;
  location / {
    return 301 https://google.com/;
  }
}

#

So thats fine?

#

Cool

brave mantle
#

Why are you using default_server

shrewd sand
#

Idk

brave mantle
#

well perhaps you should learn what that does

#

also, 443 is HTTPS, and you have no SSL configuration there

shrewd sand
#

Is there a way to allow the same ssl for all in less lines?

#

Instead of copying and pasting all the time

brave mantle
#

What? No, you should have a separate cert for each (sub)domain ideally

shrewd sand
#

Ok

#

@brave mantle i wanna try and get a hastebin server setup with all of this. Do you know a good tutorial i can follow?

brave mantle
#

Nope, but read the hastebin docs

shrewd sand
#

Ok

#

Will try xd

native tide
native tide
#

eh I'm stupid

#

it was on http by default

strong sonnet
#

@deep cave hey I discovered using an old version of aiohttp<3.0 works correctly. Must be a bug in it I guess

deep cave
#

huh, interesting. glad you figured it out.

strong sonnet
#

@deep cave well... I didn't figure it out.... Next step is to check out aiohttp and see if I can fix it in there and then submit a patch :p (urrgghhh rabbit-hole)

#

I think I've found the issue by looking at the diffs... I think

native tide
#

hey guys I'm having trouble setting up https with nginx & Waitress the WSGI server

#

when I try to go to my domain I just end up at the welcome to nginx page

#

here is my nginx configuration

#

serve(app, host='0.0.0.0', port=80,url_scheme="https")

#

thanks in advance btw 😄

native tide
#

some guy helped me out with nginx

#

thanks 😃

pale relic
#

Hi guys I was hoping to get a python web developer for a partnership

#

Anyone up for it?

#

DM me

mighty crow
#

not sure if this is the best place to ask but would comparing the time between heartbeat requests and acks be a viable option for measuring the network latency?

pale relic
#

@mighty crow maybe, but python may not be the best language for that

mighty crow
#

what might be?

unborn terrace
#

@pale relic Python is more than okay, unless he wants to measure nanosecond-wise latencies

pale relic
#

Well for extremely precise timing python is not what you want, but I guess if it is ok to have estimates, python should be more than ok

unborn terrace
#

Unless you are into HFT you never have such requirements

pale relic
#

or doing some precise science experiment

mighty crow
#

ultra-high precision wouldnt be important for me

#

im just aiming to track any spikes that might occur

native tide
#

@mighty crow C

#

C++

#

Systems languages

#

not python

mighty crow
#

interesting
well ignoring the language choice is the idea sound?

#

i wonder if pinging it instead would make a difference

pale relic
#

Well I guess you couldn't

#

*could

#

Do that, however, there are better options available

#

But as a consept there is nothing wrong with that

mighty crow
#

after some brainstorming it does seem like a fine approach

#

thanks for the help

oblique steeple
#

does anyone use spyder for flask development?