How to specify host and port in python

python

#1

Hello there
First let me say that I am a n00b newbie who is trying to learn python in corporate… I’m getting there but there is so much I don’t know.
And now for our feature presentation:

When I run my rss scraper, I’m suddenly told to specify the port and host.
Is there any specific way this is done or is it something I have to change in the preferences ?
Thank you for helping


#2

Tell your scraper to run in address 0.0.0.0 and port 8080.


#3

Hello there again…
Do you have a suggestion for doing this ?
for example :
import socket
server_address = (‘0.0.0.0’, 8080)
sock.bind(server_address)

?


#4

The

import os

os.getenv(PORT,8080) 
os.getenv(IP, 0.0.0.0)

Gives an error that says wrong syntax


#5

I believe you need the PORT and IP in ’

Try

os.getenv('PORT','8080')
os.getenv('IP','0.0.0.0')

#6

In case that doesn’t work, this stack overflow topic suggests that you use os.environ.get('PORT') so you might give that a try.


#7

Thanks, bradyowling… that worked.


#8

Hi! I still didn’t get it.
Did you use
os.environ.get(‘PORT’,8080)
os.environ.get(‘IP’,0.0.0.0)
??